实验1 C语言输入输出和简单程序编写

实验任务1

task1.1.c,task1.2.c的源码,运行测试结果如下

#include<stdlib.h>

int main()
{
    printf(" o \n");
    printf("<H>\n");
    printf("I I\n");

    printf(" o \n");
    printf("<H>\n");
    printf("I I\n");

    system("pause");
    
    return 0;
}
task1.1.c

#include<stdlib.h>

int main()
{
    printf(" o     o \n");
    printf("<H>   <H>\n");
    printf("I I   I I\n");

    system("pause");
    
    return 0;
}
task1.2.c

 

实验任务2

task2.c的源码,运行测试结果如下

#include<stdlib.h>
#include<math.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");

    system("pause");
    return 0;
}
task2.C

 

实验任务3

task3.c的源码,运行测试结果如下

#include<stdlib.h>

int main()
{
    char ans1,ans2;
    
    printf("每次课前认真预习,课后及时复习了没?(输入y或Y表示有,输入n或N表示没有):\n");
    ans1 = getchar();

    getchar();

    printf("动手敲代码实践了没?(输入y或Y表示敲了,输入n或N表示没敲):\n");
    ans2 = getchar();

    if((ans1 == 'y'||ans1 == 'Y') && (ans2 == 'y'||ans2 == 'Y'))
        printf("\n(罗马不是一天建成的,继续保持哦)\n");
    else
        printf("\n(罗马不是一天毁灭的,我们来建设吧)\n");

    system("pause");

    return 0;}
task3.C

 

实验任务4

task4.C的源码,运行测试结果如下

#include<stdlib.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);

    system("pause");
    return 0;
}
task4.C

 

实验任务5

task5.C的源码,运行测试结果如下

#include<stdlib.h>

int main()
{
    int year;
    year =1e9/(365*24*60*60);
    printf("%d\n",year);

    system("pause");
    return 0;
}
task5.C

 

实验任务6

task6.C的源码,运行测试结果如下

 

#include<stdlib.h>
#include<math.h>

int main()
{
    double x,ans;

    while(scanf("%lf",&x)!=EOF)
    {
    ans = pow(x,365);
    printf("%.2f %.2f",x,ans);
    printf("\n");
    }

    system("pause");
    return 0;
}
task6.C

 

实验任务7

task7.C的源码,运行测试结果如下

#include<math.h>

int main()
{
    double F,C;

    while(scanf("%lf",&C)!=EOF)
    {
    F=9*C/5+32;
    printf("%.2f %.2f\n", C,F);
    printf("\n");
    }

    system("pause");
    return 0;
}
task7.C

 

实验任务8

task8.C的源码,运行测试结果如下

#include<stdlib.h>
#include<math.h>

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

    while(scanf("%lf %lf %lf",&a,&b,&c)!=EOF)
    {
    s =(a+b+c)/2;
    area=sqrt(s*(s-a)*(s-b)*(s-c));
    printf("%.3f %.3f %.3f %.3f",a,b,c,area);
    printf("\n");
    }

    system("pause");
    return 0;
}
task8.C

 

posted @ 2025-03-10 10:30  DownJackring  阅读(12)  评论(0)    收藏  举报