实验1C语言开发环境使用和数据类型,运算符,表达式

实验1

task1.c

代码:

#include <stdio.h>
#include <stdlib.h>
int main()
{
    printf(" O \n");
    printf("<H>\n");
    printf(" I \n");
    printf(" O \n");
    printf("<H>\n");
    printf(" I \n");
    system("pause"); 
    return 0;
}

运行结果:

task1_2.c

代码:

 1 #include <stdio.h>
 2 
 3 int main()
 4 {
 5     // 打印第一个字符小人
 6     printf("  O   O\n");
 7     printf(" <H> <H>\n");
 8     printf("  I   I\n");
 9 
10     system("pause");
11 
12     return 0;
13 }

 

运行结果;

实验2

代码:

 

#include <stdio.h>

int main() {
    double a, b, c;

    // 输入三边边长
    scanf("%lf%lf%lf", &a, &b, &c);

    // 判断能否构成三角形
    if (a + b > c && a + c > b && b + c > a)
        printf("能构成三角形\n");
    else
        printf("不能构成三角形\n");

    return 0;
}

运行结果:

实验3

代码;

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

运行结果:

实验4

代码:

 1 #include<stdio.h>
 2 
 3 int main()
 4 {
 5     double x, y;
 6     char c1, c2, c3;
 7     int a1, a2, a3;
 8 
 9     scanf("%d%d%d", &a1, &a2, &a3);
10     printf("a1 = %d, a2 = %d, a3 = %d\n", a1, a2, a3);
11 
12     scanf("%c%c%c", &c1, &c2, &c3); 
13     printf("c1 = %c, c2 = %c, c3 = %c\n", c1, c2, c3);
14 
15     scanf("%lf%lf", &x, &y);
16     printf("x = %lf, y = %lf\n", x, y);
17 
18     return 0;
19 }

运行结果:

实验5

代码:

 1 #include <stdio.h>
 2 #include <math.h> 
 3 
 4 int main() 
 5 {
 6    int year;
 7    year=1000000000/(60*60*24*365);
 8    printf("10亿秒约等于%d年\n",year);
 9    system("pause");
10    return 0;
11 
12 
13 }

 

 

 

运行结果:

实验6

task6_1.c

代码;

 1 #include <stdio.h>
 2 #include <math.h>
 3 #include <stdlib.h>
 4 
 5 int main() 
 6 {
 7     double x, ans;
 8     scanf("%lf", &x);
 9     ans = pow(x, 365);
10     printf("%.2f的365次方为:%.2f\n", x, ans);
11     system("pause");
12     return 0;
13 }

运行结果:

task6_2.c

代码:

 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次方为:%.2f\n", x, ans);
12         printf("\n");
13     }
14     system("pause");
15     return 0;
16 }

运行结果;

实验7

代码:

 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 #include<math.h>
 4 int main()
 5 {
 6     double C,F;
 7     while(scanf("%1f",&C)!=EOF)
 8     {
 9         F=9*C/5+32;
10         printf("当摄氏度为%.2f时,其对应的华氏度为%.2f\n",C,F);
11     }
12     system("pause");
13     return 0;
14 }

运行结果:

实验8

代码;

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <math.h>
 4 
 5 int main()
 6 {
 7     double a, b, c, s, p;
 8     while (scanf("%lf %lf %lf", &a, &b, &c) != EOF) 
 9     {
10         s = (a + b + c) / 2;
11         p = pow(s * (s - a) * (s - b) * (s - c),0.5);
12         printf("a = %f, b = %f, c = %.0f, area = %.3f\n\n", a, b, c, p);
13     }
14     system("pause");
15     return 0;
16 }

运行结果:

 

posted @ 2025-03-09 14:57  赵可妍  阅读(37)  评论(0)    收藏  举报