首页 > 编程语言 >实验一_C语言输入输出和简单程序应用编程实验报告

实验一_C语言输入输出和简单程序应用编程实验报告

时间:2024-03-13 21:03:19浏览次数:26  
标签:10 实验报告 return int 输入输出 C语言 pause printf include

实验任务一

task1_1

 

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

 

task1_2

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

 

实验任务二

 

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

 

实验任务三

 

 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 
 4 int main()
 5 {
 6     char ans1,ans2;
 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     system("pause");
21     return 0;
22 }
View Code

 

 

 

 A:当把line9去掉以后,程序在第二次输入后结束; 上一行代码让ans1=getchar(),line9可以让程序等待下一个输入字符。

 

实验任务四

 

 1 int main()
 2 {
 3     double x,y;
 4     char c1,c2,c3;
 5     int a1,a2,a3;
 6 
 7     scanf("%d%d%d",&a1,&a2,&a3);//error
 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);//error
14     printf("x=%lf,y=%lf",x,y);
15 
16     system("pause");
17     return 0;
18 }
View Code

 

实验任务五

 

 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 
 4 int main()
 5 {
 6     int year;
 7     double sec,trueyear;
 8 
 9     sec=1000000000;
10     trueyear=sec/3600/24/365;
11     year=trueyear+0.5;
12     
13     printf("10亿秒约等于%d年\n", year);
14     system("pause");
15     return 0;
16 }
View Code

 

 

 

实验任务六

 

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

 

实验任务七

 

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

 

 

实验任务八

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

 

 

 

实验总结
1.在进行数据的运算时要注意定义的格式以及算式中数字的形式,避免得数不够精确,四舍五入发生错误。
2.在输入数值时,尤其是char类型的几个数据间慎用空格,避免造成识别错误。

 

标签:10,实验报告,return,int,输入输出,C语言,pause,printf,include
From: https://www.cnblogs.com/nuistjcy/p/18071489

相关文章

  • 实验1_C语言输入输出和简单程序应用编程实验报告
    实验任务一1.task1_1点击查看代码#include<stdio.h>#include<stdlib.h>intmain(){ printf("0\n"); printf("<H>\n"); printf("II\n"); printf("0\n"); printf("<H>\n"); printf(&quo......
  • 实验1 C语言输入输出和简单程序编写
    task1_11#include<stdio.h>2intmain()3{4printf("O\n");5printf("<H>\n");6printf("II\n");78printf("O\n");9printf("<H>\n");10......
  • 实验1 C语言输入输出和简单程序编写
    任务1任务2任务3任务3(去掉getchar)任务4任务5任务6任务7任务8......
  • C语言入门学习 --- 7.结构体
    文章目录第七章结构体1.结构体的声明1.1结构的基础知识1.2结构的声明1.3结构成员的类型1.4结构体变量的定义和初始化2.结构体成员的访问2.1结构体变量访问成员2.2结构体指针访问指向变量的成员3.结构体传参配套练习:第七章结构体1.结构体类型的声明2.结构体初始......
  • C语言入门学习 --- 9.编程练习题
    1.正整数A和正整数B的最小公倍数是指能被A和B整除的最小的正整数,设计一个算法,求输入A和B的最小公倍数。输入描述:输入两个正整数A和B。输出描述:输出A和B的最小公倍数。输入:57输出:35#include<stdio.h>intmain(){ inta=0; intb=0; inti=0; scanf("%d%......
  • C语言自学笔记6----C语言的循环语句
    C语言的循环语句C语言for循环在编程中,循环用于重复代码块,直到满足指定条件为止。C语言编程具有三种循环类型:for循环while循环do…while循环for循环(Loop)for循环的语法为:示例for(initializationStatement;testExpression;updateStatement){//循环体内......
  • C语言最重要的知识点(2)
    第二章第一节:数据输出(一)(二)1、使用printf和scanf函数时,要在最前面加上#include“stdio.h”2、printf可以只有一个参数,也可以有两个参数。(选择题考过一次)3、printf(“第一部分”,第二部分 );把第二部分的变量、表达式、常量以第一部分的形式展现出来!4、printf(“a=%d,b=%d”,12......
  • C语言的内存管理
    前言这篇文章给大家简单介绍一下C语言中内存管理。一、C语言内存管理的简图二、内存的细分 内存分为:① 栈区② 堆区③ 静态存储区④ 常量存储区⑤ 代码区1.栈区(Stack):① 由编译器自动分配释放。② 利用栈存储一些临时变量,包括函数参数、函数内部局部变量、返回......
  • C语言自学笔记4----C语言存储类
    C语言存储类存储类定义C程序中变量/函数的范围(可见性)和生命周期。这些说明符放置在它们所修饰的类型之前。下面列出C程序中可用的存储类:autoregisterstaticexternauto存储类auto存储类是所有局部变量默认的存储类。{intmount;autointmonth;}上面的示......
  • 实验1 C语言开发环境使用和数据类型、运算符、表达式
    1#include<stdio.h>2intmain()3{4printf("o\n");5printf("<H>\n");6printf("II\n");78return0;9}#include<stdio.h>intmain(){printf("oo\n"......