实验1
1.垂直小人源码
#include <stdio.h>
#include <stdlib.h>
int main(){
int i;
for(i=0;i<=1;i++){
printf(" O\n");
printf("<H>\n");
printf("I I\n");
}
system("pause");
return 0;
}
2.运行效果

3.水平小人源码
1 #include <stdio.h> 2 #include <stdlib.h> 3 int main (){ 4 printf(" O O\n"); 5 printf("<H> <H>\n"); 6 printf("I I I I\n"); 7 8 system("pause"); 9 return 0; 10 }
4.运行效果

二.实验二
1 #include <iostream> 2 #include<stdio.h> 3 #include<math.h> 4 int main() 5 { 6 float a, b, c; 7 8 scanf_s("%f%f%f", &a, &b, &c); 9 10 if (a+b>c || a+c>b || b+c>a) { 11 printf("能构成三角形\n"); 12 } 13 else 14 { 15 printf("不能构成三角形\n"); 16 } 17 }

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


四.实验任务4
#include<stdio.h>
int main()
{
double x, y;
char c1, c2, c3;
int a1, a2, a3;
scanf_s("%d%d%d",&a1,&a2,&a3);
printf("a1 = %d,a2 = %d,a3 = %d\n",a1,a2,a3);
scanf_s("%c%c%c",&c1,&c2,&c3);
printf("c1 = %c, c2 = %c, c3 = %c\n", c1, c2, c3);
scanf_s("%lf,%lf", &x, &y);
printf("x = %f, y = %lf\n", x, y);
return 0;
}

五.实验任务5
1 #include<stdio.h> 2 int main() 3 { 4 int year; 5 float second; 6 second = 1000000000; 7 year = second/31536000; 8 9 printf("十亿秒约等于%d年", year); 10 }

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

七.实验任务7
1 #define _CRT_SECURE_NO_WARNINGS 2 #include<stdio.h> 3 #include<math.h> 4 5 int main() 6 { 7 double x, ans; 8 9 while (scanf("%lf", &x) != EOF) 10 { 11 ans = x * 9 / 5 + 32; 12 printf("摄氏度c = %f时,华氏度f = %f",x,ans); 13 } 14 15 16 return 0; 17 }

八.实验任务8
1 #define _CRT_SECURE_NO_WARNINGS 2 #include<stdio.h> 3 #include<math.h> 4 5 int main() 6 { 7 double a, b, c, s, area; 8 9 while (scanf("%lf %lf %lf", &a, &b, &c)) 10 { 11 s = (a + b + c) / 2; 12 area = sqrt(s * (s - a) * (s - b) * (s - c)); 13 printf("a = %lf, b = %lf., c = %lf., area = %lf\n", a, b, c, area); 14 printf("\n"); 15 } 16 17 18 return 0; 19 }


浙公网安备 33010602011771号