实验1

实验1
源代码
1
#include<math.h> 2 int main() 3 { 4 printf(" 0\n"); 5 printf("<H>\n"); 6 printf("I I\n"); 7 printf(" 0\n"); 8 printf("<H>\n"); 9 printf("I I\n"); 10 return 0; 11 }
1 #include<math.h>
2 int main()
3 {
4     printf(" 0    0\n");
5     printf("<H>  <H>\n");
6     printf("I I  I I\n");
7     return 0;
8 }

 

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

 

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

问题,如果去掉,则无法输入ans2,getchar()用于读取回车空格等

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

 

#include<stdio.h>
int main()
{
    int year;
    double n;
    n = 1000000000.0 / 31536000.0;
     if (n - (int)n >= 0.5)
     {
         year = (int)n + 1;
     }
     else year = (int)n;

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

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

#include<stdio.h>
int main()
{
    double C, F;
    while (scanf("%lf", &C) != EOF)
    {
        F = 9 * C / 5 + 32;
        printf("摄氏度c=%.2f", C);
        printf("华摄度F=%.2f", F);
        printf("\n");
    }
    return 0;
}

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

 

posted @ 2024-09-25 19:46  zhj910  阅读(10)  评论(0编辑  收藏  举报