首页 > 其他分享 >实验一

实验一

时间:2023-10-03 14:55:58浏览次数:24  
标签:lf int double scanf 实验 printf include

task1_1.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 = %lf, y = %lf\n",x, y);
    
    return 0;
}

运行结果

 task1_2.c

源代码

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

运行结果

 

task2.c

源代码

#include <stdio.h>
int main()
{
    float a, b, c;
    // 输入三边边长
    scanf("%f%f%f", &a, &b, &c);
    // 判断能否构成三角形
    // 补足括号里的逻辑表达式
    if (a + b > c && a + c > b && b + c > a)
        printf("能构成三角形\n");
    else
        printf("不能构成三角形\n");
    system("pause");
    return 0;
}

运行结果

 

 task3.c

源代码

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

运行结果

 

task4.c

源代码

 1 #include<stdio.h>
 2 #include<stdlib.h>
 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     getchar();
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     system("pause");
19     return 0;
20 }

 

运行结果

 

 task5.c

源代码

#include <stdio.h>
int main()
{
    int year;

    const double second = 1e9;
    double temp = ((second / 3600) / 24) / 365;
    if (temp - (int)temp < 0.5) {
        year = (int)temp;
    }
    else {
        year = (int)temp + 1;
    }

    printf("10亿秒约等于%d年\n", year);
    system("pause");
    return 0;
}

运行结果

 task6.c

源代码

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

 

运行结果

 

 task7.c

源代码

#include <stdio.h>

int main()
{
    double f;
    double c;

    while (scanf("%lf", &c) != EOF) {
        f = 9.0 / 5.0 * c + 32.0;
        printf("摄氏度c = %.2lf时, 华氏度f = %.2lf\n", c, f);
        printf("\n");
    }

    return 0;
}

 

运行结果

 task8.c

源代码

#include <stdio.h>
#include <math.h>

int main()
{
    double a, b, c;
    double s;
    double 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("a = %d, b = %d, c = %d, area = %.3lf\n", (int)a, (int)b, (int)c, area);
        printf("\n");
    }

    return 0;
}

 

运行结果

 

标签:lf,int,double,scanf,实验,printf,include
From: https://www.cnblogs.com/dmjq/p/17741137.html

相关文章

  • 【231003CHEM-1】电解硫酸铜溶液 化学方程式虽简单 但稳定实验还需要多次尝试
    电解硫酸铜用以湿法炼铜或是制备稀硫酸,书本上的反应方程式倒是很简单,具体如下:阴极:2Cu2++4e-==2Cu阳极:2H2O-4e-==4H++O2总方程式:2Cu2++2H2O=通电=2Cu+O2+4H+或2CuSO4+2H2O=通电=2Cu+O2+2H2SO4(以上公式来自https://qb.zuoyebang.com/xfe-question/questi......
  • 实验1 C语言输入输出和简单程序编写
    实验任务11.1代码1//打印一个字符小人23#include<stdio.h>4intmain()5{6printf("O\n");7printf("<H>\n");8printf("II\n");9printf("O\n");10printf("<H>......
  • 实验一
    #include<stdio.h>intmain(){printf("0\n");printf("<H>\n");printf("II\n");return0;}#include<stdio.h>intmain(){floata,b,c;scanf("%f%f%f",&a,......
  • 实验任务8
    #include<stdio.h>#include<math.h>intmain(){doublea,b,c,s,area;while(scanf("%lf",&a)!=EOF&&scanf("%lf",&b)!=EOF&&scanf("%lf",&c)!=EOF){s=(a+b+c)/2;......
  • 实验任务6
    #include<stdio.h>#include<math.h>intmain(){doublex,ans;while(scanf("%lf",&x)!=EOF){ans=pow(x,365);printf("%.2f的365次方:%.2f\n",x,ans);}return0;} ......
  • 实验任务7
    #include<stdio.h>intmain(){doublex,ans;while(scanf("%lf",&x)!=EOF){ans=x*9.0/5.0+32;printf("ÉãÊ϶Èc=%.2f",x);printf("£¬");printf("»ªÊ϶Èf=%.2f\n",ans);}return0;}......
  • 实验任务5
    #include<stdio.h>intmain(){intyear;doubleyear1=1000000000.0/365.0/24.0/3600.0;doubleyear2=year1;while(year2>=1){year2--;}if(year2>=0.5){year=int(year1)+1;}else{year=int(year1);}printf(&......
  • 实验任务4
    #include<stdio.h>intmain(){doublex,y;charc1,c2,c3;inta1,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);prin......
  • 实验1 C语言输入输出和简单程序编写
    1.实验任务1task1_1.c源代码1#include<stdio.h>2intmain()3{4printf("o\n");5printf("<H>\n");6printf("II\n");7printf("o\n");8printf("<H>\n"......
  • 实验1c语言的简单输入输出和简单程序编写
    实验1#include<stdio.h>#include<stdlib.h>intmain(){printf("0\n");printf("<H>\n");printf("II\n");system("pause");return0;}实验2#include<stdio.h>#include<stdlib.......