首页 > 编程语言 >实验1—C语言输入输出和简单程序应用编写

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

时间:2023-09-30 22:12:43浏览次数:47  
标签:main return int 输入输出 C语言 实验 printf 编写 include

1.实验1

实验1_1源代码

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

 

实验1_2运行结果截图

 

2.实验2

实验2_1源代码

 1 #include <stdio.h>
 2 #include<stdlib.h>
 3 int main()
 4 {
 5 float a, b, c;
 6 // 输入三边边长
 7 scanf("%f%f%f", &a, &b, &c);
 8 // 判断能否构成三角形
 9 // 补足括号里的逻辑表达式
10 if(a+b>c&&b+c>a&&a+c>b)
11     printf("能构成三角形\n");
12 else
13     printf("不能构成三角形\n");
14 system("pause");
15 return 0;
16 }

实验2_2运行结果截图

3.实验3

实验3_1源代码

#include <stdio.h>
#include<stdlib.h>
int main()
{
char ans1, ans2; // 用于保存用户输入的答案
printf("每次课前认真预习、课后及时复习了没? (输入y或Y表示有,输入n或N表示没有) :");
ans1 = getchar(); // 从键盘输入一个字符,赋值给ans1
getchar(); // 思考这里为什么要加这一行。试着去掉这一行,看看对运行有没有影响。
printf("\n动手敲代码实践了没? (输入y或Y表示敲了,输入n或N表示木有敲) : ");
ans2 = getchar();
if ((ans1=='Y'||ans1=='y')&&(ans2=='Y'||ans2=='y'))
    printf("\n罗马不是一天建成的, 继续保持哦:)\n");
else
    printf("\n罗马不是一天毁灭的, 我们来建设吧\n");
   system ("pause");
   return 0;
}

 

实验3_2运行结果截图

4.实验4

实验4_1源代码

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

实验4_2运行结果截图

5.实验5

实验5_1源代码

1 #include<stdio.h>
2 int main()
3 {
4     int year;
5     scanf_s("%d", &year);
6     (int) (year = (double)year / 365 / 24 / 60 / 60 + 0.5);
7     printf("10亿秒约等于%d年\n", year);
8     return 0;
9 }

实验5_2运行结果截图

6.实验6

实验6_1源代码

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

 

实验6_2运行结果截图

7.实验7

实验7_1源代码

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

实验7_2运行结果截图

8.实验8

实验8_1源代码

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

实验8_2运行结果截图

 

标签:main,return,int,输入输出,C语言,实验,printf,编写,include
From: https://www.cnblogs.com/SunYuTing/p/17735907.html

相关文章

  • Qt编写网易云界面 (9) -----歌词界面、部分功能实现
    最近就是就是完成一些小功能,歌词界面,部分按钮的点击事件,歌词列表等;效果如图:视频页面歌单列表:歌词界面:点击歌曲详情页面:歌曲列表代码listform:#ifndefLISTFORM_H#defineLISTFORM_H#include<QVector>#include<QWidget>#include<QString>namespaceUi{classLi......
  • 实验1 C语言输入输出和简单程序编写
    task1.c代码1#include<stdio.h>2intmain()3{4printf("O\n");5printf("<H>\n");6printf("II\n");7return0;8}task1.c运行截图 task1-1.c代码1#include<stdio.h>2int......
  • NO.3 C语言实现贪吃蛇游戏(Linux)
     一、简易说明:实现了初步的游戏模型,可以玩,但有一些细节bug没有解决。用WASD控制方向  二、源代码+头文件1#include<stdio.h>2#include"snake.h"34567intmain(intargc,constchar*argv[])8{91011system("cl......
  • 实验1 C语言开发环境使用和数据类型.运算符.表达式
    task1.c代码#include<stdio.h>intmain(){printf("O\n");printf("<H>\n");printf("II\n");return0;} 运行结果  task1_2.c代码 #include<stdio.h>intmain(){printf(&quo......
  • Linux下C语言操作网卡的几个代码实例?特别实用
    前面写了一篇关于网络相关的文章:如何获取当前可用网口。《简简单单教你如何用C语言列举当前所有网口!》那么如何使用C语言直接操作网口?比如读写IP地址、读写MAC地址等。一、原理主要通过系统用socket()、ioctl()、实现intsocket(intdomain,inttype,intprotocol);功能:......
  • C语言输入输出和简单程序编写
    Task1.11#include<stdio.h>2#include<stdlib.h>3intmain(){4printf("0\n");5printf("<H>\n");6printf("II\n");7printf("0\n");8printf("<H>......
  • 6. 用Rust手把手编写一个wmproxy(代理,内网穿透等), 通讯协议源码解读篇
    用Rust手把手编写一个wmproxy(代理,内网穿透等),通讯协议源码解读篇项目++wmproxy++gite:https://gitee.com/tickbh/wmproxygithub:https://github.com/tickbh/wmproxy事件模型的选取OS线程,简单的一个IO对应一个系统级别的线程,通常单进程创建的线程数是有限的,在线程与......
  • 实验1 C语言输入输出和简单程序编写
    一、实验目的二、实验准备三、实验内容四、实验结论task1task1_1代码:1#include<stdio.h>23intmain()4{5printf("O\n");6printf("<H>\n");7printf("II\n");89printf("O\n");10......
  • 实验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>\......
  • 编写循环小案例
    打印等腰三角形第1次推导publicclasstest9{publicstaticvoidmain(String[]args){//行数inta=3;System.out.println();System.out.print("");System.out.print("");System.out.print(&q......