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

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

时间:2023-09-30 14:11:23浏览次数:36  
标签:10 main return int 输入输出 C语言 printf 编写 include

task1.c代码

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

task1.c运行截图

 task1-1.c代码

 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     return 0; 
11 } 

task1-1.c运行截图

 task1-2.c代码

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     return 0; 
8 } 

task1-2.c运行截图

  task2.c代码

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

task2.c运行截图

task3.c代码

 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  }
15  return 0;
16 }

task2.c运行截图

 task4.c代码

 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  
10   scanf(" %c%c%c", &c1, &c2, &c3);
11  printf("c1 = %c, c2 = %c, c3 = %c\n", c1, c2, c3);
12  
13  scanf("%lf%lf",&x,&y); 
14  printf("x = %lf, y = %lf\n",x, y);
15 
16  return 0;
17 }

 task4.c运行截图

  task5.c代码

 1 #include<stdio.h>
 2 int main()
 3 {
 4     int year;
 5     float second = 1;
 6     int n = 9;
 7     while (n>0){
 8         second *=10;
 9         n--;
10     }
11     year = second /(3600*24*365)+0.5;
12     printf("10亿秒约等于%d年\n",year);
13     return 0;
14 }

 task5.c运行截图

   task6-1.c代码

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

 task6-1.c运行截图

    task6-2.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    return 0;
12 }

task6-2.c运行截图

    task7.c代码

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

task7.c运行截图

     task8.c代码

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

task8.c运行截图

 

标签:10,main,return,int,输入输出,C语言,printf,编写,include
From: https://www.cnblogs.com/homeh/p/17737787.html

相关文章

  • 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......
  • 学习C语言的第十三天
    用递归的方法计算n的阶乘#include<stdio.h>intmain(){intn=0;intmul=1;scanf("%d",&n);for(inti=1;i<=n;i++){mul=mul*i;}printf("%d\n",mul);return0;}以上代码是直接算n的阶乘#include<stdio.h>int......
  • 编写运行一个Python程序
    1.5.1基于PythonIDLE运行程序(1)找到安装Python所在的目录。(2)进入子目录./Lib/idlelib。(3)找到并双击idle.bat文件,会弹出idle窗口(此时即表示已进入PythonShell)。1.5.2命令行式交互运行文件(1)打开文本编辑器(如Notepad),编写代码并保存为helloworld.py文件。(2)打开cmd......