实验1 C语言开发环境使用和数据类型,运算符,表达式
实验一:
1.
源代码:
1 #include<stdio.h> 2 #include<stdlib.h> 3 int main (){ 4 printf(" O \n"); 5 printf("<H>\n"); 6 printf("I I\n"); 7 printf(" O \n"); 8 printf("<H>\n"); 9 printf("I I\n"); 10 system("pause"); 11 return 0; 12 }

2.
源代码:
1 #include<stdio.h> 2 #include<stdlib.h> 3 int main (){ 4 printf(" O 0\n"); 5 printf("<H> <H>\n"); 6 printf("I I I I\n"); 7 system("pause"); 8 return 0; 9 }

实验二:
源代码:
1 #include<stdio.h> 2 #include<stdlib.h> 3 4 int main(){ 5 double a,b,c; 6 scanf("%lf%lf%lf",&a,&b,&c); 7 if((a+b)>c&&(a+c)>b&&(b+c)>a) 8 printf("能够成三角形"); 9 else 10 printf("不能构成三角形"); 11 system("pause"); 12 return 0; 13 }



实验三:
源代码:
1 #include<stdio.h> 2 #include<stdlib.h> 3 4 int main() 5 { 6 char ans1,ans2; 7 printf("每次课前认真预习,课后及时复习了没?(输入y或Y表示有,输入n或N表示没有)"); 8 ans1=getchar(); 9 getchar(); 10 printf("\n动手敲代码实践了没?(输入y或Y表示敲了,输入n或N表示木有敲)"); 11 ans2=getchar(); 12 if((ans1=='y'|| ans1 == 'Y')&&(ans2=='Y'||ans2=='y')) 13 printf("\n罗马不是一天建成的,继续保持哦:)\n"); 14 else 15 printf("\n罗马不是一天毁灭的,我们来建设吧\n"); 16 system("pause"); 17 return 0; 18 }




实验四:
源代码:
1 #include<stdio.h> 2 #include<stdlib.h> 3 4 int main() 5 { 6 double x, y, z; 7 char c1, c2, c3; 8 int a1, a2, a3; 9 10 scanf_s("%d%d%d", &a1, &a2, &a3); 11 printf("a1=%d,a2=%d,a3=%d\n",a1,a2,a3); 12 13 scanf("%c%c%c", &c1, &c2, &c3); 14 printf("c1 = %c, c2 = %c, c3 = %c\n", c1, c2, c3); 15 16 scanf("%lf,%lf", &x, &y); 17 printf("x = %f, y = %lf\n", x, y); 18 19 system("pause"); 20 return 0; 21 22 }

实验五:
源代码:
1 #include<stdio.h> 2 #include<stdlib.h> 3 4 int main() 5 { 6 int year; 7 int second = 1; 8 int i = 1; 9 double a,b; 10 for (i = 1; i < 10; i++) 11 { 12 second *= 10; 13 } 14 year = second / (60 * 60 * 24 * 365); 15 a = second - year * 60 * 60 * 24 * 365; 16 b = a / (60 * 60 * 24 * 365); 17 if (b >= 0.5) 18 year += 1; 19 printf("10亿秒约等于%d年\n", year); 20 system("pause"); 21 return 0; 22 }

实验六:
源代码:
1 #include<stdio.h> 2 #include<math.h> 3 #include<stdlib.h> 4 5 int main() 6 { 7 double x, ans; 8 while(scanf("%lf", &x)!=EOF) 9 { 10 ans = pow(x, 365); 11 printf("%.2f的365次方是:%.2lf\n", x, ans); 12 printf("\n"); 13 } 14 system("pause"); 15 return 0; 16 }

实验七:
源代码:
1 #include<stdio.h> 2 #include<stdlib.h> 3 4 int main() 5 { 6 double c, f; 7 while (scanf_s("%lf", &c) != EOF) 8 { 9 f = 9 * c / 5 + 32; 10 printf("摄氏度c=%.2f时,华氏度f=%.2f\n", c, f); 11 12 } 13 system("pause"); 14 return 0; 15 }

实验八:
源代码:
1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<math.h> 4 5 int main() 6 { 7 int a, b, c; 8 double s, area; 9 while (scanf_s("%d%d%d", &a, &b, &c) != EOF) 10 { 11 s = (double)(a + b + c)/ 2; 12 area = sqrt(s*(s - a)*(s - b)*(s - c)); 13 printf("a=%d,b=%d,c=%d\n", a, b, c); 14 printf("area=%f", area); 15 } 16 system("pause"); 17 return 0; 18 }


浙公网安备 33010602011771号