实验1
task2.c
1 #include <stdio.h> 2 3 int main() 4 { 5 double a, b, c; 6 7 scanf("%lf%lf%lf", &a, &b, &c); 8 9 if((a+b>c)&&(b+c>a)&&(a+c>b)) 10 printf("能构成三角形\n"); 11 else 12 printf("不能构成三角形\n"); 13 14 return 0; 15 16 }

task1.c
//打印一个字符小人 #include <stdio.h> int main() { printf(" O O\n"); printf("<H> <H>\n"); printf("I I I I\n"); return 0; }


task3.c
#include <stdio.h> int main() { char ans1, ans2; printf("每次课前认真预习、课后及时复习了没? "); ans1 = getchar(); getchar(); printf("\n动手敲代码实践了没? "); ans2 = getchar(); if (ans1 == 'y'||ans2 =='Y') printf("\n罗马不是一天建成的, 继续保持哦:)\n"); else printf("\n罗马不是一天毁灭的, 我们来建设吧\n"); return 0; }

task4.c
#include <stdio.h> int main() { double x, y; char c1, c2, c3; int a1, a2, a3; scanf("%d%d%d", &a1, &a2, &a3); printf("a1 = %d, a2 = %d, a3 = %d\n", a1, a2, a3); scanf("%c%c%c", &c1, &c2, &c3); printf("c1 = %c, c2 = %c, c3 = %c\n", c1, c2, c3); scanf("%lf,%lf", &x, &y); printf("x = %f, y = %lf\n",x, y); return 0;

#include <stdio.h> int main() { int year; int seconds_in_year = 365 * 24 * 60 * 60; long long total_seconds = 1000000000; double years = (double)total_seconds / seconds_in_year; year = (int)(years + 0.5); printf("10亿秒约等于%d年\n", year); return 0; }

task6.c
#include <stdio.h> #include <math.h> int main() { double x, ans; scanf("%lf", &x); ans = pow(x, 365); printf("%.2f的365次方: %.2f\n", x, ans); return 0; }



#include <stdio.h> int main() { double C, F; // 多组输入,直到按下ctrl+z终止 while (scanf("%lf", &C) != EOF) { // 计算华氏温度:F = 9/5*C + 32 F = 1.8 * C + 32; // 保留两位小数输出 printf("%.2f\n", F); } return 0; }

task8.c
#include <stdio.h> #include <math.h> int main() { double a, b, c, s, area; while (scanf("%lf %lf %lf", &a, &b, &c) != EOF) { // 计算半周长 s s = (a + b + c) / 2; // 利用海伦公式计算面积 area = sqrt(s * (s - a) * (s - b) * (s - c)); // 保留三位小数输出面积 printf("%.3f\n", area); } return 0; }


浙公网安备 33010602011771号