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

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

时间:2023-10-06 17:57:16浏览次数:41  
标签:10 源代码 return int 输入输出 C语言 printf 编写 include

实验任务1

task1.c

源代码:

 1 //打印一个字符小人
 2 
 3 #include <stdio.h>
 4 int main()
 5 { 
 6    printf(" 0\n");
 7    printf("<H>\n");
 8    printf("I I\n");
 9    
10    
11     return 0;
12  } 

 

运行截图:

task1_1.c

源代码:

 1 //打印一个字符小人
 2 
 3 #include <stdio.h>
 4 int main()
 5 { 
 6    printf(" 0\n");
 7    printf("<H>\n");
 8    printf("I I\n");
 9    
10    printf(" 0\n");
11    printf("<H>\n");
12    printf("I I\n");   
13    return 0;
14    
15 }  

运行截图:

task1_2.c

源代码:

 1 //打印一个字符小人
 2 
 3 #include <stdio.h>
 4 int main()
 5 { 
 6    printf(" 0      0\n");
 7    printf("<H>    <H>\n");
 8    printf("I I    I I\n");
 9    
10   
11    return 0;
12    
13 }   

运行截图:

实验任务2

源代码:

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

 

运行截图:

 

实验任务3

源代码:

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

运行截图:

实验任务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     getchar();
12     
13     scanf("%c%c%c",&c1,&c2,&c3);
14     printf("c1=%c,c2=%c,c3=%c\n",c1,c2,c3);
15     getchar();
16     
17     scanf("%lf,%lf",&x,&y);
18     printf("x=%f,y=%f\n",x,y);
19     
20     return 0;
21 }

运行截图:

实验任务5

源代码:

 1 #include <stdio.h>
 2 
 3 int main()
 4 {
 5     int year=1000000000;
 6     year=year+31536000/2;
 7     year=year/31536000;
 8     printf("%d",year);
 9     return 0;
10 }

运行截图:

实验任务6

源代码:

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

运行截图:

实验任务7

源代码:

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

运行截图:

实验任务8

源代码:

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

运行截图:

 

标签:10,源代码,return,int,输入输出,C语言,printf,编写,include
From: https://www.cnblogs.com/st5114-/p/17735897.html

相关文章

  • C语言阶乘for循环语句的使用
    #include<stdio.h>intmain(){inti=0,n=0;ret=1;scanf_s("%d",&n);//scanf_s作用是避免在编译器中出现不安全影响代码编译 for(i=1;i<=n;i++)   { ret=ret*i;    } printf("%d\n",ret); return0;}用于输入n的阶乘利用for语句解决求1~10阶乘的......
  • C语言求1~n的阶乘的和的进阶优化
    #include<stdio.h>intmain(){ intret=1; intsum=0; intn=0;for(n=1;n<=10;n++)//10可以变成任意值 { ret=ret*n; sum=sum+ret; } printf("%d",sum); return0;}......
  • 实验1 C语言输入输出和简单程序编写
    一1_1.c1#include<stdio.h>23intmain()4{5printf("o\n");6printf("<H>\n");7printf("II\n");8printf("o\n");9printf("<H>\n");10......
  • 实验1 C语言输入输出和简单程序编写
    实验1实验1-11//打印一个字符小人23#include<stdio.h>4intmain()5{6printf("O\n");7printf("<H>\n");8printf("II\n");9printf("O\n");10printf("<H>\......
  • 【C语言入门】快速排序函数的应用
    快速排序函数qsortvoidqsort(void*base,typenitems,typesize,int(cmp)(constvoid*p1,constvoid*p2));参数说明:base  指针要排序的数组的首元素指针nitems  数组元素的总个数size  数组中每一个元素的字节大小cmp  函数指针(用来比较两个元素的函数)比......
  • 求最大公约数的三种方法:C语言
    求最大公约数之穷举法求最大公约数之穷举法inta,b,c,gcd;scanf("%d%d",&a,&b);c=a<b?a:b;inti=1;for(i=c;i>=1;i--){if(a%i==0&&b%i==0){gcd=i;printf("GCD=%d\n",gcd);......
  • sv的LSB 使用+SV的protect类型+RAL模型的lock原因+C语言结构体中的冒号用法+uvm版本在
    sv的LSB使用https://blog.csdn.net/gsjthxy/article/details/90722378等价关系[LSB+:STEP]=[LSB+STEP:LSB]伪代码:bit[1023:0]mem;bit[7:0]data;j=0..100mem[j*8+:8]=data;//[7:0],[15:8],[23:16]SV的protect类型https://blog.csdn.net/qq_37573794/ar......
  • 常见的C语言执行效率优化方法
    C语言之心效率优化写代码时考虑代码的执行效率是一个好习惯,嵌入式开发多年,让自己养成了这样的习惯。优化C语言代码的执行效率是一项重要的任务,可以通过多种方法和注意事项来实现。下面列出了一些常用的方法和注意事项,并结合具体实例进行详细讲解:选择合适的数据结构使用合适的数......
  • C语言逗号表达式和赋值表达式
    C语言逗号表达式和赋值表达式笔试常考这个,没办法#include<iostream>usingnamespacestd;intmain(intargc,charconst*argv[]){inta=0,b=0,c=0,d=0;//1.逗号表达式/*表达式1,表达式2,表达式3……表达式n;逗号表达式的求解过程是......
  • 实验1 C语言输入输出和简单程序编写
    1.实验任务11.c1#include<stdio.h>23intmain()4{5printf("o\n");6printf("<H>\n");7printf("II\n");89return0;10}1-1.c1#include<stdio.h>23in......