第五次课后作业

作业1.1:C语言标准库的目的是什么?编写一个小程序,说明如何使用标准库里的数学函数;
1.1目的是降低编程人编程的复杂性。


[cpp]  view plain copy
  1. #include "stdafx.h"  
  2. #include<math.h>  
  3.   
  4.   
  5. int _tmain(int argc, _TCHAR* argv[])  
  6. {double a;  
  7. long b;  
  8. a=0.5;  
  9. b= sin (a);  
  10. printf("%d",b);  
  11.   
  12.  return 0;  
  13. }  


1.2

程序代码

[cpp]  view plain copy
  1. #include "stdafx.h"  
  2. float chufa(float a,float b, float c)  
  3. {float d;  
  4. d=a/(b+c);  
  5. return d;  
  6. }  
  7.   
  8. void main()  
  9. {float x,y,z;  
  10. float h;  
  11. x=234.0;  
  12. y=1.0;  
  13. z=257.0;  
  14. h=chufa(x,y,z);  
  15. printf("234/(1+257)=%f\n",h);  
  16. x=1065.0;  
  17. y=24.0;  
  18. z=13.0;  
  19. h=chufa(x,y,z);  
  20. printf("1065/(24+13)=%f\n",h);  
  21.   
  22. }  

运行结果

1.3

程序代码

[cpp]  view plain copy
  1. #include "stdafx.h"  
  2. #include <math.h>  
  3. #define PI 3.141592  
  4.   
  5. void main()  
  6. {double a;  
  7. double b;  
  8. a=log(sqrt(2*PI-1))/log(5.0);  
  9. printf("%lf\n",a);  
  10. b=exp(sqrt(PI-1));  
  11. printf("%lf\n",b);  
  12. }  


输出结果

2

程序代码

[cpp]  view plain copy
  1. #include "stdafx.h"  
  2.   
  3.   
  4. int _tmain(int argc, _TCHAR* argv[])  
  5.   
  6. {  
  7.     int a;  
  8. for(;;)  
  9. {  
  10. printf("你的年龄是");  
  11. scanf_s("%d",&a);  
  12.   
  13.   
  14.       
  15.   
  16. if (a<18)  
  17.     printf("未成年\n");  
  18. else  
  19.     printf("成年\n");  
  20.   
  21.   
  22. }  
  23.   
  24. }  


运行结果

3.1
属于第二个if,直觉

3.2

[cpp]  view plain copy
  1. if (x > 0)   
  2. {  
  3. if (y > 1) z = 1;   
  4. else z = 2;    
  5. }  


4

while代码

[cpp]  view plain copy
  1. #include "stdafx.h"  
  2.   
  3.   
  4. void main()  
  5. {int i;  
  6. i=1;  
  7.     while(i<=10)  
  8.     {   printf ("%d\n",i);  
  9.         i=i+1;  
  10.      }  
  11. }  


改后

for代码

[cpp]  view plain copy
  1. #include "stdafx.h"  
  2.   
  3.   
  4. void main()  
  5. {int i;  
  6. i=1;  
  7.     for (i=1;i<=10;i=i+1)  
  8.     {   printf ("%d\n",i);  
  9.          
  10.      }  
  11. }  


5.1

程序代码

[cpp]  view plain copy
  1. #include "stdafx.h"  
  2. #include<math.h>  
  3. #define PI 3.1415926  
  4.   
  5. double s1(double r)  
  6. {   double s;  
  7. s=PI*r*r;  
  8. return s;  
  9. }  
  10.   
  11. void main()  
  12.     {double a;  
  13.     double b;  
  14.     a=1.0;  
  15.         b=s1(a);  
  16.     printf ("S1=%lf\n",b);  
  17.     a=2.0;  
  18.         b=s1(a);  
  19.     printf ("S1=%lf\n",b);  
  20. }  


运行结果

5.2
把INT 改成FLOAT

6

程序代码

[cpp]  view plain copy
  1. #include "stdafx.h"  
  2. #include<math.h>  
  3.   
  4. double s1(double a,double b,double c)  
  5. {   double s;  
  6. s=a * b * sin( c/180.0 * 3.14 )/2.0 ;  
  7. return s;  
  8. }  
  9.   
  10.   
  11. void main()  
  12. {int i;  
  13. double h,x,y,z;  
  14.     for(i=0;i<=4;i=i+1)  
  15.     {printf("请输入第%d组三角形的参数:",i);  
  16.     scanf_s("%lf  %lf  %lf",&x,&y,&h);  
  17.     printf("第%d组三角形的实参为:A边长%.2lf B边长 %.2lf 夹角 %.2lf\n",i,x,y,h);  
  18.     z=s1(x,y,h);  
  19.     printf("第%d组三角形的面积为:%.2lf\n",i,z);  
  20.     printf("--------------分割线-------------\n");  
  21.     }  
  22. }  


运行结果

7

感想:同感

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值