作业1.1:C语言标准库的目的是什么?编写一个小程序,说明如何使用标准库里的数学函数;
1.1目的是降低编程人编程的复杂性。
- #include "stdafx.h"
- #include<math.h>
- int _tmain(int argc, _TCHAR* argv[])
- {double a;
- long b;
- a=0.5;
- b= sin (a);
- printf("%d",b);
- return 0;
- }
1.2
程序代码
- #include "stdafx.h"
- float chufa(float a,float b, float c)
- {float d;
- d=a/(b+c);
- return d;
- }
- void main()
- {float x,y,z;
- float h;
- x=234.0;
- y=1.0;
- z=257.0;
- h=chufa(x,y,z);
- printf("234/(1+257)=%f\n",h);
- x=1065.0;
- y=24.0;
- z=13.0;
- h=chufa(x,y,z);
- printf("1065/(24+13)=%f\n",h);
- }
运行结果
1.3
程序代码
- #include "stdafx.h"
- #include <math.h>
- #define PI 3.141592
- void main()
- {double a;
- double b;
- a=log(sqrt(2*PI-1))/log(5.0);
- printf("%lf\n",a);
- b=exp(sqrt(PI-1));
- printf("%lf\n",b);
- }
输出结果
2
程序代码
- #include "stdafx.h"
- int _tmain(int argc, _TCHAR* argv[])
- {
- int a;
- for(;;)
- {
- printf("你的年龄是");
- scanf_s("%d",&a);
- if (a<18)
- printf("未成年\n");
- else
- printf("成年\n");
- }
- }
运行结果
3.1
属于第二个if,直觉
3.2
- if (x > 0)
- {
- if (y > 1) z = 1;
- else z = 2;
- }
4
while代码
- #include "stdafx.h"
- void main()
- {int i;
- i=1;
- while(i<=10)
- { printf ("%d\n",i);
- i=i+1;
- }
- }
改后
for代码
- #include "stdafx.h"
- void main()
- {int i;
- i=1;
- for (i=1;i<=10;i=i+1)
- { printf ("%d\n",i);
- }
- }
5.1
程序代码
- #include "stdafx.h"
- #include<math.h>
- #define PI 3.1415926
- double s1(double r)
- { double s;
- s=PI*r*r;
- return s;
- }
- void main()
- {double a;
- double b;
- a=1.0;
- b=s1(a);
- printf ("S1=%lf\n",b);
- a=2.0;
- b=s1(a);
- printf ("S1=%lf\n",b);
- }
运行结果
5.2
把INT 改成FLOAT
6
程序代码
- #include "stdafx.h"
- #include<math.h>
- double s1(double a,double b,double c)
- { double s;
- s=a * b * sin( c/180.0 * 3.14 )/2.0 ;
- return s;
- }
- void main()
- {int i;
- double h,x,y,z;
- for(i=0;i<=4;i=i+1)
- {printf("请输入第%d组三角形的参数:",i);
- scanf_s("%lf %lf %lf",&x,&y,&h);
- printf("第%d组三角形的实参为:A边长%.2lf B边长 %.2lf 夹角 %.2lf\n",i,x,y,h);
- z=s1(x,y,h);
- printf("第%d组三角形的面积为:%.2lf\n",i,z);
- printf("--------------分割线-------------\n");
- }
- }
运行结果
7
感想:同感