爱问知识人 爱问教育 医院库

用C 输入直角三角形的两条直角边长

首页

用C++输入直角三角形的两条直角边长

用C++输入直角三角形的两条直角边长,调用平方根函数sqrt来求斜边的长度。

提交回答
好评回答
  • 2008-11-08 21:58:00
      #include<iostream> #include<stdio。h> #define max 50     //定义最大字符数为50的全局变量 max#include "math。h"void func(char string[max]){ int i=0;   while(string[i]!='\0' && i<50) {     if(string[i]>='0' && string[i]<='9')    i+=1;      else   {      printf("%s不是数字。
      \n",string); break; }}} void main(){ qw: char string1[max]; char string2[max]; printf("请输入直角三角形的两个邻边\n"); scanf("%s%s",&string1,&string2); func(string1); func(string2); int a=atoi(string1); int b=atoi(string2); double l1=pow(a,2); double l2=pow(b,2); double sum=sqrt(l1+l2); printf("邻边为%s和%s的直角三角形斜边为: %f\n",string1,string2,sum); goto qw;}这个程序可以判断输入的数据数否为数字。
      

    g***

    2008-11-08 21:58:00

其他答案

    2008-11-09 19:16:00
  • #include <iostream>#include <math>#inlcude <cstdlib>int main(){  float a,b;  do  {   cout<<"(a,b):";   cin>>a>>b;  }while(!(a>0&&b>0));  cout<<"斜边长度:%f\n",sqrt(a*a+b*b)); system("pause"); return 0;}

    徐***

    2008-11-09 19:16:00

  • 2008-11-08 21:38:00
  • include <iostream> #include <math> #inlcude <cstdlib> int main() { float a,b;

    d***

    2008-11-08 21:38:00

类似问题

换一换

相关推荐

正在加载...
最新问答 推荐信息 热门专题 热点推荐
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200

热点检索

  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
返回
顶部
帮助 意见
反馈

确定举报此问题

举报原因(必选):