Task1.1
1 #include<stdio.h> 2 #include<stdlib.h> 3 int main(){ 4 printf(" 0 \n"); 5 printf("<H>\n"); 6 printf("I I\n"); 7 printf(" 0 \n"); 8 printf("<H>\n"); 9 printf("I I\n"); 10 system("pause"); 11 return 0; 12 }
Task1.1截图
Task1.2
1 #include<stdio.h> 2 #include<stdlib.h> 3 int main(){ 4 printf(" 0 0\n"); 5 printf("<H> <H>\n"); 6 printf("I I I I\n"); 7 system("pause"); 8 return 0; 9 }
Task1.2截图
Task2
1 #include<stdio.h> 2 #include<stdlib.h> 3 int main(){ 4 float a, b, c; 5 scanf("%f%f%f",&a,&b,&c); 6 if(a+b>c&&a+c>b&&b+c>a){ 7 printf("能构成三角形"); 8 } 9 else{ 10 printf("不能构成三角形"); 11 } 12 system("pause"); 13 return 0; 14 }
Task2截图
Task3
1 #include<stdio.h> 2 #include<stdlib.h> 3 int main(){ 4 char ans1,ans2; 5 printf("每次课前认真预习,课后及时复习了没?(输入Y或y表示有,输入n或N表示没有):"); 6 ans1 = getchar();//由于回车键也是一种字符,此行代码为了取到正确输入结果,防止回车键干扰运行结果 7 getchar(); 8 printf("\n动手敲代码实践了没?(输入y或Y表示敲了,输入n或N表示没有敲):"); 9 ans2 = getchar(); 10 if((ans1 == 'y'||ans1 =='Y')&&(ans2 == 'y'||ans2 == 'Y')) { 11 printf("\n罗马不是一天建成的,继续保持哦!\n"); 12 } 13 else{ 14 printf("罗马不是一天毁灭的,我们来建设吧!\n"); 15 } 16 system("pause"); 17 return 0; 18 }
Task3中getchar();意义:由于回车键也是一种字符,此行代码为了取到正确输入内容,防止回车键干扰运行结果
Task3截图
Task4
1 #include<stdio.h> 2 int main(){ 3 double x, y; 4 char c1, c2, c3; 5 int a1, a2, a3; 6 scanf("%d%d%d",&a1,&a2,&a3);/*少了&字符,不能获取到输入的数字*/ 7 printf("a1 = %d,a2 = %d,a3 = %d\n",a1,a2,a3); 8 scanf("%c%c%c",&c1,&c2,&c3); 9 printf("c1 = %c,c2 = %c,c3 = %c\n",c1,c2,c3); 10 scanf("%lf,%lf",&x,&y);/*f是单精度浮点型,而lf才是双精度浮点型与上文double对应*/ 11 printf("x = %lf,y = %lf\n",x,y); 12 return 0; 13 14 }
Task4截图
Task5
1 #include<stdio.h> 2 int main(){ 3 int year; 4 double c = 10.0*10*10*10*10*10*10*10*10/60/60/24/365; 5 int b = c; 6 double a = c-b; 7 if(a>=0&&a<0.5){ 8 year = b; 9 } 10 else { 11 year = b+1; 12 } 13 printf("10亿秒约等于%d年\n",year); 14 return 0; 15 }
Task5截图
Task6
#include<stdio.h> #include<math.h> int main(){ double x,ans; while(scanf("%lf",&x)!=EOF){ ans = pow(x,365); printf("%.2f的365次方: %.2f\n",x,ans); } return 0; }
Task6截图
Task7
1 #include<stdio.h> 2 int main(){ 3 double c,f; 4 while(scanf("%lf",&c)!=EOF){ 5 f = c*9.0/5+32; 6 printf("摄氏度c = %.2lf时,华氏度f = %.2lf\n",c,f); 7 } 8 return 0; 9 }
Task7截图
Task8
1 #include<stdio.h> 2 #include<math.h> 3 int main(){ 4 int a,b,c; 5 double s,area; 6 while(scanf("%d %d %d",&a,&b,&c) != EOF){ 7 s = (a+b+c)/2.0; 8 area = sqrt(s*(s-a)*(s-b)*(s-c)); 9 printf("a = %d,b = %d,c = %d,area = %.3lf\n",a,b,c,area); 10 } 11 }
Task8截图
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
完成后总结:
总体来说,蛮有意思的。写代码,发现错误,再寻找错误,反思错误。如此反复,我感觉有不少的收获。若此练习,熟能生巧,对今后的学习大有裨益!!!
标签:10,截图,main,int,输入输出,C语言,printf,编写,include From: https://www.cnblogs.com/nuist6/p/17737627.html