首页 > 其他分享 >实验一

实验一

时间:2024-09-28 22:35:33浏览次数:1  
标签:lf 10 return int 实验 printf include

实验任务1:

源代码(1)

 1 #include <stdio.h>
 2 int main()
 3 {
 4     printf(" O \n");
 5     printf("<H>\n");
 6     printf("I I\n");
 7     printf(" O \n");
 8     printf("<H>\n");
 9     printf("I I\n");
10     
11     return 0;
12 }

 

源代码(2)

1 #include <stdio.h>
2 int main()
3 {
4  printf(" O   O\n");
5  printf("<H> <H>\n");
6  printf("I I I I\n");
7 
8  return 0;
9 }

实验任务2:

源代码:

 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 }

 

 

实验任务3:

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

回答问题:

ans2无法输入,getchar可以返回再输入,不加则不能再输入

实验任务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 
 3 int main()
 4 {
 5     int year;
 6     
 7     double second=1000000000;
 8     double num=second/365/24/60/60;
 9     year = (int)(num +0.5);
10     
11     printf("10亿秒约等于%d年\n", year);
12     return 0;
13 }

实验任务6:

源代码:

 1 #include <stdio.h>
 2 #include <math.h>
 3 
 4 int main()
 5 {
 6     double x,ans;
 7     
 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     
15     return 0;
16 }

实验任务7:

源代码:

 1 #include <stdio.h>
 2 #include <math.h>
 3 
 4 int main()
 5 {
 6     double c,f;
 7     
 8     while(scanf("%lf",&c) != EOF)
 9     {
10         f=1.8*c+32;
11         printf("摄氏度c = %.2f时,华氏度f = %.2f\n", c, f);
12         printf("\n");
13     }
14     
15     return 0;
16 }

实验任务8:

源代码:

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

 

标签:lf,10,return,int,实验,printf,include
From: https://www.cnblogs.com/chenya17/p/18431793

相关文章

  • 实验一
    任务一1.1源代码#include<stdio.h>intmain(){printf("O\n");printf("<H>\n");printf("II\n");return0;}task1_1.c#include<stdio.h>intmain(){printf("O\n");......
  • 实验1
    task1-1.c#include<stdio.h>intmain(){printf("o\n");printf("<H>\n");printf("II\n");printf("o\n");printf("<H>\n");printf("II\n");......
  • 零基础学STM32(四)-LED灯闪烁实验
    本项目讲解所用工程均使用stm32f103C8T6芯片HAL库版本。原理讲解本节内容我们讲解点亮LED灯闪烁实验,简单来讲就是实现LED电平翻转实现LED灯亮灭的过程。我们点亮LED灯需要给LED输入一个高电平,熄灭LED灯则给LED灯输入一个低电平,将两个电平状态不断重复即可实现LED的闪烁。初......
  • 实验
    试验任务一:源代码(竖直方向):1#include<stdio.h>2intmain()3{4printf("o\n");5printf("<H>\n");6printf("II\n");7printf("o\n");8printf("<H>\n");......
  • 实验1
        任务1源代码(1)1#include<stdio.h>2intmain(){3printf("0\n");4printf("<H>\n");5printf("II\n");6return0;7}  源代码(2)1#include<stdio.h>2intmain(){3......
  • 实验1
    任务1#include<stdio.h>intmain(){printf("o\to\n");printf("<H>\t<H>\n");printf("II\tII\n");return0;}#include<stdio.h>intmain(){printf("o......
  • 实验1
    任务1:水平方向#include<stdio.h>intmain(){printf("O  O\n");printf("<H><H>\n");printf("IIII\n");return0;}竖直方向#include<stdio.h>intmain(){printf("O\n");printf("&......
  • 《DNK210使用指南 -CanMV版 V1.0》第二十七章 摄像头图像调整实验
    第二十七章摄像头图像调整实验1)实验平台:正点原子DNK210开发板2)章节摘自【正点原子】DNK210使用指南-CanMV版V1.03)购买链接:https://detail.tmall.com/item.htm?&id=7828013987504)全套实验源码+手册+视频下载地址:http://www.openedv.com/docs/boards/k210/ATK-DNK210.html5......
  • 实验1
    task1.1c1#include<stdio.h>2intmain()3{4printf("O\n");5printf("<H>\n");6printf("II\n");7printf("O\n");8printf("<H>\n");9printf(......
  • java计算机毕业设计的实验室仪器管理(开题+程序+论文)
    本系统(程序+源码)带文档lw万字以上 文末可获取一份本项目的java源码和数据库参考。系统程序文件列表开题报告内容研究背景随着科技的飞速发展,实验室作为科学研究和技术创新的核心场所,其管理效率与信息化水平直接影响到科研活动的顺利进行与成果产出。传统的手工管理模式在......