C语言实训习题
- 格式:pdf
- 大小:354.26 KB
- 文档页数:10
C语言实训题目录综合实训选题1--简单的文本编辑器 (2)综合实训选题2 --简易计算器 (4)综合实训选题3--工资排名 (6)综合实训选题4--用 C 语言实现键盘画图 (7)综合实训选题5 --模拟病人看病系统 (8)综合实训选题6--五子棋 (10)综合实训选题7--报数游戏 (13)综合实训选题8--学生成绩管理程序 (26)综合实训选题1--简单的文本编辑器一.功能要求:编制一个简单的单行文本编辑器程序,具有文本的插入、删除、替换功能。
要求设置编辑命令如下:1 .E ------ 指定所要编辑的文件2 .Q------- 结束编辑3 .R-------- 替换文本用R 命令后继的K 行正文替代原始正文中的M 行到N 行的正文内容;命令格式:R K M NK 行正文其中K 、M 、N 均为大于零的整数;4 .I-------- 插入文本用I 命令后继的K 行正文插入原始正文中的M 行之后;命令格式:I K MK 行正文其中K 、M 均为大于零的整数;5 .D-------- 删除文本用D 命令将原始正文中第M 行到N 行的正文内容删除;命令格式:D M N其中M 、N 均为大于零的整数;说明:程序只限于编辑较短的文本文件(*.txt ), 每行不超过80 个字符,总行数不超过200 行,正文行从0 开始编号。
三.本设计涉及的知识点:1 .数组2 .指针和指针数组3 .文件中字符串的读出和写入4 .函数的定义5 .字符函数的使用四.设计指导:1 .需定义函数,分别实现插入、删除、替换和退出;2 .插入时,把M 行以后的后移,然后在M 行处插入K 行;使用strcpy() 函数;3 .删除时把N 行后续行覆盖要M—N 行;4 .替换时先把M—N 行的内容删除,再插入K 行,以实现替换;5 .退出时提示保存,然后将修改后内容写入文件;6 .注意每个函数中对输入参数M,N,K 的合理性检查。
综合实训选题 2 --简易计算器一、功能要求设计一个简易计算器 , 实现四则运算二、相关知识函数选择结构循环结构将字符转换成数值三、程序要求1. 编制函数 displaycalculator, 显示计算器面板2. 编制函数 getdata, 获取计算数据3. 编制计算函数 calculate4. 编制计算结果函数 displayresult.四、设计指导1、显示计算器面板,只要用 printf 函数画出面板即可。
C语言实训题及参考答案第一题:编写一个程序,将输入的两个整数进行加法运算,并输出结果。
参考答案:```c#include <stdio.h>int main() {int num1, num2, result;printf("请输入两个整数:");scanf("%d %d", &num1, &num2);result = num1 + num2;printf("加法结果:%d", result);return 0;}```第二题:编写一个程序,判断输入的整数是否为偶数,并输出“是”或“否”。
参考答案:```c#include <stdio.h>int main() {int num;printf("请输入一个整数:");scanf("%d", &num);if (num % 2 == 0) {printf("是");} else {printf("否");}return 0;}```第三题:编写一个程序,计算输入字符串的长度,并输出结果。
参考答案:```c#include <stdio.h>#include <string.h>int main() {char str[100];int length;printf("请输入一个字符串:");scanf("%s", str);length = strlen(str);printf("字符串长度:%d", length);return 0;}```第四题:编写一个程序,将输入的字符串反转,并输出结果。
参考答案:```c#include <stdio.h>#include <string.h>int main() {char str[100];int i, length;printf("请输入一个字符串:");scanf("%s", str);length = strlen(str);for (i = length - 1; i >= 0; i--) {printf("%c", str[i]);}return 0;}```第五题:编写一个程序,将输入的数组元素按从小到大的顺序排序,并输出结果。
C语言实训题目
以下是几个C语言实训题目:
1. 编写一个C程序,使用for循环计算所有100以内的奇数的和。
2. 编写一个C程序,读取用户输入的两个数字,计算它们的和、差、积和商,并输出结果。
3. 编写一个C程序,使用while循环读取用户输入的数字,直到用户输入0为止,并计算输入数字之和,最后输出结果。
4. 编写一个C程序,读取用户输入的一段英文文字,将其中的每个单词首字母大写,并输出结果。
5. 编写一个C程序,使用指针实现一个简单的链表,完成添加节点、删除节点、搜索节点等基本操作。
6. 编写一个C程序,实现一个简单的计算器,支持加、减、乘、除等基本运算。
7. 编写一个C程序,读取用户输入的一段文章,统计其中每个字母出现的次数,并按照字母表顺序输出。
8. 编写一个C程序,实现一个简单的学生信息管理系统,包括添加、修改、查询、删除等功能。
9. 编写一个C程序,读取用户输入的一个整数N,使用递归实现N 的阶乘计算,并输出结果。
10. 编写一个C程序,使用函数指针实现菜单式交互,用户可以通过输入数字选择想要执行的操作,例如计算器、学生信息管理系统等。
1.数据类型a.输入一个小数点后有多位数字的小数,实现将其保留三位小数,并输出;(3.14159 →3.142,10.123456 →10.123)#include<stdio.h>main(){double b,d;printf("请输入一个小数:");scanf("%lf",&b);printf("输出原来的数:%f\n",b);b*=1000;b+=0.5;b=(int)b;d=b/1000;printf("输出现在的数:%.3lf\n0",d);}b.输入一个4位整数,求其得各位数字的平方和;(1234 → 1+4+9+16=30)#include<stdio.h>main(){int n,sum=0,i,t;printf("请输入一个四位整数:\n");scanf("%d",&n);for(i=0;i<4;i++){t=n%10;n/=10;sum+=t*t;}printf("%d\n",sum);}c.定义字符型变量ch,写出六种给ch赋值字符’A’的代码;#include<stdio.h>main(){char ch;ch='A';ch=65;ch=0x41;ch=0101;ch='\101';ch='\x41';}d.编写程序输出26组大小写字母;(AaBbCc……….XxYyZz)#include<stdio.h>main(){int i;for(i=65;i<91;i++){printf("%c",i);printf("%c",i+32);}printf("\n");}e.定义浮点型变量f1、f2,为f1赋值10的-30次,为f2赋值10的30次#include<stdio.h>main(){double f1,f2;f1=10e-30;f2=10e30;printf("%lf\n%lf\n",f1,f2);}f.定义一个单精度浮点型变量f和一个双精度浮点型变量d,为f和d都赋值3.14159265358979323846264338327950288,输出f和d得值,要求保留20位小数,观察输出结果;#include<stdio.h>void main(){float f;double d;f=3.14159265358979323846264338327950288;d=3.14159265358979323846264338327950288;printf("f=%.20f\nd=%.20lf\n",f,d);}g.输入华氏温度求摄氏温度。
C语言实训练习题项目1:输入三角形边长,求面积。
设三角形的三个边分别为a、b、c,周长一半为s,面积为area,则s=1/2*(a+b+c), area=sqrt(s*(s-a)*(s-b)*(s-c))。
项目2:从键盘输入大写字母,用小写字母输出项目3:输入一个三位整数,依次输出该数的正(负)号和百位、十位、个位数字。
项目4:输入两个整数a、b,将它们交换,例如a为3,b为5,交换后a为5,b为3。
项目5:输入一个华氏温度,输出对应的摄氏温度。
输出取1位小数。
转换公式为c=5/9*(f-32)项目6:鸡兔同笼问题。
已知鸡兔总头数为H,总脚数为F,求鸡兔各有多少只?分析:依题意设鸡有x只,兔有y只。
项目1:根据圆柱体的半径和高,计算圆周长、圆面积、圆柱体表面积、圆柱体体积。
项目2:从键盘输入两个整数a和b,如果a大于b则交换两数,否则不交换,最后输出两个数。
项目3:将任意三个整数按从大到小的顺序输出。
项目4:给一个不多于4位的正整数,求出它是几位数,逆序打印出各位数字。
项目5:求分段函数的值,如果x≥0, y=2x+1,否则, y=0 。
项目6:模拟自动饮料机。
按屏幕所示功能,输入所选择的合法数字,输出可获得的相应饮料名称。
运行效果:=============自动饮料机============== 1.可口可乐 2.雪碧 3.芬达 4.百事可乐5.非常可乐请按1-5按钮选择饮料:3 你获得一听芬达项目7:当企业利润P等于或低于0.5万元时,奖金为利润的1%;当0.5<P≤1万元时,超过0.5万元部分的奖金为利润的1.5%,0.5万元以下仍按1%计算;当1<P≤2万元时,1万元以下部分仍按前面的方法计算,超过1万元的部分其奖金按利润的2%计算;当2<P≤5万元时,2万元以下部分仍按前面的方法计算,超过2万元部分的奖金按利润的2.5%计算;当5<P≤10万元时,5万元以下部分仍按前面的方法计算,超过5万元部分的奖金按利润的3%计算;当P>10万元时,10万元以下部分仍按前面的方法计算,超过10万元部分按3.5%计算。
c语言练习题
在学习C语言编程过程中,适当的练习题目可以巩固所学的知识,
并提升对C语言的理解和应用能力。
以下是一些适用于初学者的C语
言练习题目,可以帮助您检验自己的编程水平和解决问题的能力。
练习一:输出姓名和年龄
要求:编写一个C程序,在控制台输出自己的姓名和年龄。
练习二:计算圆的面积
要求:编写一个C程序,根据用户输入的半径,计算并输出圆的面积。
练习三:计算矩形的面积和周长
要求:编写一个C程序,根据用户输入的长和宽,计算并输出矩形
的面积和周长。
练习四:判断奇偶数
要求:编写一个C程序,判断用户输入的数是奇数还是偶数,并在
控制台输出相应的结果。
练习五:计算两数之和
要求:编写一个C程序,要求用户输入两个整数,并计算它们的和,然后在控制台输出结果。
练习六:找出最大数
要求:编写一个C程序,要求用户输入三个数,然后找出其中的最大数,并在控制台输出结果。
练习七:判断闰年
要求:编写一个C程序,判断用户输入的年份是否为闰年,并在控制台显示结果。
练习八:计算阶乘
要求:编写一个C程序,要求用户输入一个正整数,然后计算并输出它的阶乘。
练习九:逆序输出字符串
要求:编写一个C程序,要求用户输入一个字符串,然后按逆序输出该字符串。
练习十:生成九九乘法表
要求:编写一个C程序,生成九九乘法表,并在控制台输出结果。
通过完成以上的C语言练习题,您可以巩固对C语言的理解,并提高编程能力。
希望这些练习题对您有所帮助,让您更好地掌握C语言编程。
继续努力学习,不断提升自己的技能!。
大学c语言实践考试题及答案一、选择题(每题2分,共20分)1. C语言中,用于定义一个整型变量的关键字是:A. intB. floatC. doubleD. char答案:A2. 下列哪个选项是C语言中的合法标识符?A. 2variableB. variable2C. -variableD. variable$答案:B3. 在C语言中,以下哪个是正确的字符串字面量?A. "Hello World"B. 'Hello World'C. "Hello World'D. 'Hello World'答案:A4. C语言中,以下哪个运算符用于逻辑与操作?A. &&B. ||C. !D. ~答案:A5. 下列哪个函数用于计算两个数的和?A. max()B. pow()C. sqrt()D. sum()答案:D6. 在C语言中,以下哪个关键字用于定义函数?A. intB. voidC. structD. function答案:B7. C语言中,以下哪个选项是正确的二维数组声明?A. int array[3][4];B. int array[3,4];C. int array(3)(4);D. int array[3 4];答案:A8. 下列哪个选项是C语言中正确的条件语句?A. if x > 0 then y = x;B. if x > 0 { y = x; }C. if x > 0 y = x;D. if (x > 0) y = x;答案:D9. 在C语言中,以下哪个选项是正确的无限循环?A. for(;;)B. while(1)C. do {} while(1)D. All of the above答案:D10. 下列哪个选项是C语言中正确的函数声明?A. int function();B. function int();C. int function int();D. int function(int x);答案:D二、填空题(每空2分,共20分)1. 在C语言中,使用________关键字可以定义一个指针变量。
安装Visual C ++6.0下载请从群里下载Microsoft Visual Studio.rar。
将下载的文件Microsoft Visual Studio.rar解压后即可使用。
请直接运行文件“Microsoft Visual Studio\Common\MSDev98\Bin\MSDEV.EXE”实验一认识C语言【实验目的】1.熟悉C程序设计编程环境Visual C ++,掌握运行一个C程序设计的基本步骤,包括编辑、编译、连接和运行。
编辑:编写源程序文件.c编译:生成目标文件.obj连接:生成可执行文件.exe运行:执行.exe文件。
2.掌握C语言程序设计的基本框架,能够编写简单的C程序。
3.了解程序调试的思想,能找出并改正C程序中的语法错误。
【实验内容】1-1 在磁盘上新建一个文件夹,用于存放C程序,文件夹的名字可以是学号,如D:\3050888。
1-2 编程示例,在屏幕上显示一个短句“Hello World!”。
源程序# include <stdio.h>void main( ){printf("Hello World! \n");}运行结果Hello World!作为第一个实验,在Visual C++编程环境下,以上述C语言源程序为例,介绍运行一个C 程序的基本步骤,请读者按照以下步骤操作。
(1)启动VC++执行“开始”—>“程序”—>“Microsoft Visual Studio 6.0”—> “Microsoft Visual C++ 6.0”,进入VC++编程环境(如图1.1所示)。
图1.1 VC++窗口(2)新建文件执行“文件/File”—>“新建/New”,单击“文件/Files”选项卡(如图 1.2所示),先在“文件/File name”栏中输入test,把C源(程序)文件命名为test.cpp,在“目录/Location”框中选择你已经建立的文件夹,如,D:\3050888,然后选中“C++ Sourse Files”,单击“确定”按钮,在D:\3050888下就新建了文件test.cpp,并显示编辑窗口和信息窗口(如图1.3所示)。
c语言习题及详解答案C语言是一种广泛使用的编程语言,以其结构化、可移植和高效性而著称。
以下是一些C语言的习题以及相应的详解答案。
# 习题1:求和问题编写一个C程序,输入两个整数,输出它们的和。
解答:```c#include <stdio.h>int main() {int num1, num2, sum;printf("请输入两个整数:");scanf("%d %d", &num1, &num2);sum = num1 + num2;printf("这两个整数的和是:%d\n", sum);return 0;}```# 习题2:判断素数编写一个C程序,判断一个整数是否为素数。
解答:```c#include <stdio.h>#include <math.h>int isPrime(int n) {if (n <= 1) return 0;for (int i = 2; i <= sqrt(n); i++) {if (n % i == 0) return 0;}return 1;}int main() {int num;printf("请输入一个整数:");scanf("%d", &num);if (isPrime(num)) {printf("%d 是素数。
\n", num);} else {printf("%d 不是素数。
\n", num);}return 0;}```# 习题3:字符串反转编写一个C程序,输入一个字符串,然后输出它的反转。
解答:```c#include <stdio.h>#include <string.h>void reverseString(char str[]) {int len = strlen(str);for (int i = 0; i < len / 2; i++) {char temp = str[i];str[i] = str[len - i - 1];str[len - i - 1] = temp;}}int main() {char str[100];printf("请输入一个字符串:");scanf("%s", str);reverseString(str);printf("反转后的字符串是:%s\n", str);return 0;}```# 习题4:数组排序编写一个C程序,输入一个整数数组,然后使用冒泡排序算法对其进行排序。
实训题目1:商店商品管理系统某商店每天有进货、售货、统计销售额、计算毛利率、查看商品剩余量等业务,所以人工管理是一件非常繁琐的事情,为了快速有效地管理,该商店提出要编制一个计算机管理软件。
功能要求:循环显示如图1所示的主菜单。
选择1:创建商品档案。
每一个商品信息包括编号、品名、进价、售价、进货量、销售量、销售额、剩余数、毛利;选择2:编辑商品信息。
例如,向商品档案添加新商品、删除原有商品、处理原有商品的新进货量、新销售量、报废量;选择3:统计销售情况。
在此项中统计每种商品的销售额、剩余数、毛利(毛利=销售额-进价×销售量);选择4:查询商品信息。
如:根据品名、剩余数(小于5或大于20)进行查询; 选择5:显示商品信息。
显示方式有3种,即按原来商品顺序显示、按销售额高到底的顺序显示、按毛利高到底的顺序显示,由于商品较多,所以要求分屏显示。
选择0:退出系统。
菜单要求:(1)设计如图1_1所示的主菜单;(2)选择2时显示如图1_2所示的子菜单; (3)选择4时显示如图1_3所示的子菜单; (4)选择5时显示如图1_4所示的子菜单;主菜单和子菜单能够循环出现,每一项菜单执行之后,询问用户是否继续进行。
从子菜单可以返回到主菜单。
图1_1 某商场商品管理主菜单 |------------------------------ | | 请输入选项编号(0—5): | |------------------------------| | 1——创建商品档案 | | 2——编辑商品信息 | | 3——统计销售情况 | | 4——查询商品信息 | | 5——显示商品信息 | | 0——退出系统 | |------------------------------ | 图1_2. 编辑商品信息子菜单 |******************************| | 请输入选项编号(0—4): | |******************************| | 1——添加新商品 | | 2——删除原有商品 | | 3——修改原有商品信息 | | 4——返回 | | 0——退出 | |******************************| 图1_3 查询商品信息子菜单|******************************| | 请输入选项编号(0—3): | |******************************|| 1——按品名查询| | 2——按剩余数查询| | 3——返回 | | 0——退出||******************************|图1_4 显示商品信息子菜单|******************************|| 请输入选项编号(0—4): | |******************************| | 1——按原来顺序显示 | | 2——按销售额高底显示 | | 3——按毛利高底显示 | | 4——返回 | | 0——退出||******************************|实训题目2:音像图书租借管理系统功能要求:(1)创建音像图书库。
c语言实操题1. 编写一个C程序,要求用户输入两个整数,然后输出它们的和。
```c#include <stdio.h>int main() {int num1, num2, sum;printf("请输入两个整数:\n");scanf("%d %d", &num1, &num2);sum = num1 + num2;printf("它们的和为:%d\n", sum);return 0;}```2. 编写一个C程序,要求用户输入一个整数,然后输出它的绝对值。
```c#include <stdio.h>int main() {int num, absValue;printf("请输入一个整数:\n");scanf("%d", &num);if (num >= 0) {absValue = num;} else {absValue = -num;}printf("它的绝对值为:%d\n", absValue);return 0;}```3. 编写一个C程序,要求用户输入一个字符,然后判断该字符是大写字母、小写字母还是数字。
```c#include <stdio.h>int main() {char ch;printf("请输入一个字符:\n");scanf(" %c", &ch);if (ch >= 'A' && ch <= 'Z') {printf("该字符是大写字母\n");} else if (ch >= 'a' && ch <= 'z') {printf("该字符是小写字母\n");} else if (ch >= '0' && ch <= '9') {printf("该字符是数字\n");} else {printf("该字符不是大写字母、小写字母或数字\n");}return 0;}```4. 编写一个C程序,要求用户输入一个正整数n,然后计算并输出从1到n的累加和。
C语言实训指导习题(全)第1章习题1. C语言程序的基本结构是【】。
A) 函数B) 语句C) 字符D) 程序行2. 下列四个叙述中,正确的是【】A)在C程序中,主函数必须位于其他函数的最前面B)在C程序中,一行只能写一条语句C)C程序的基本结构是程序行D)C语句是完成程序功能的最小单位3. C语言规定,在一个C程序中,main()函数的位置是【】A)必须在开始B) 必须在最后C) 可以任意D) 必须在系统调用的库函数之后4. 以下叙述中,正确的是【】。
A) C语言程序总是从第一个定义的函数开始执行 .B) C语言程序中,要调用的函数必须在main()函数中定义C) C语言程序总是从main()函数开始执行D) C语言程序中的main()函数必须放在程序的开始部分5. 在C语言提供的合法的关键字是【】A)switch B)cher C)Case D)FLOAT6. 以下用户标识符,其中合法的是【】A) For B) 4d C) f2.G3 D) _f#第2章习题C语言所提供的五种基本数据类型包括:字符型、整型、双精度型、浮点型和【D】。
A) 指针型B)结构型C)数组型D)无值类型2. 列四组数据类型中,C语言允许的一组是【B 】A) 整型、实型、逻辑型,双精度型B) 整型、实型、字符型,无值类型C) 整型、双精度型、布尔型,无值类型D) 整型、实型、复型、字符型3. 下面均是合法整型常量的是【A 】。
A) 160 B) -0xcdf C) -01 D) -0x48a-0xffff 01a 986.12 2e5012 0xe 0668 0x4. 在C语言中,合法的字符常量是【B 】A)'\084' B)'\x43' C)'ab' D)"\0"5. 下面错误的转义字符是【A】A) '\091' B) '\\' C) '\0' D) '\''6.下面不正确的字符串常量是【A 】。
c语言实训题目(赵莹莹)题目1 学生学籍管理系统.................................................................. 错误!未定义书签。
题目2 学生选课管理系统.................................................................. 错误!未定义书签。
题目3 冒泡排序的实现与演示.......................................................... 错误!未定义书签。
题目4 汉诺塔的实现与演示.............................................................. 错误!未定义书签。
题目5 简易通讯录.............................................................................. 错误!未定义书签。
题目6:图书管理系统.......................................................................... 错误!未定义书签。
题目7:计算器的实现.......................................................................... 错误!未定义书签。
题目8:工资管理系统.......................................................................... 错误!未定义书签。
题目9 :职工信息管理系统................................................................ 错误!未定义书签。
C语言练习题及答案以下是一些C语言练习题及其答案。
这些练习题旨在帮助初学者巩固C语言的基础知识,并提供了相应的解答。
每个练习题都具有一定的难度,涵盖了C语言的不同概念和语法规则。
通过完成这些练习题,读者能够提高自己的编程能力,并更好地理解C语言的使用。
练习题1:编写一个程序,计算并输出两个整数的和。
```c#include <stdio.h>int main() {int num1, num2, sum;printf("请输入第一个整数: ");scanf("%d", &num1);printf("请输入第二个整数: ");scanf("%d", &num2);sum = num1 + num2;printf("两个整数的和是: %d\n", sum);return 0;}```练习题2:编写一个程序,接受用户输入的半径,计算并输出圆的面积和周长。
假设圆周率为3.14,使用浮点数进行计算。
```c#include <stdio.h>int main() {float radius, area, circumference;printf("请输入圆的半径: ");scanf("%f", &radius);area = 3.14 * radius * radius;circumference = 2 * 3.14 * radius;printf("圆的面积是: %.2f\n", area);printf("圆的周长是: %.2f\n", circumference);return 0;}```练习题3:编写一个程序,判断一个整数是否为奇数或偶数。
如果是奇数,则输出"奇数",否则输出"偶数"。
C语⾔实验题及参考答案实验⼀1、计算整数各位数字之和(10 分)输⼊⼀个3位正整数,将其每⼀位的数字相加,输出和。
输⼊格式:输⼊⼀个3位正整数。
变量数据类型为unsigned。
输出格式:输出整数每⼀位相加后的整数和。
输⼊样例:输出样例:【参考答案】#include ""int main(){ unsigned int a,ge,shi,bai,sum;scanf("%d",&a);ge=a%10;shi=a/10%10;bai=a/100;sum=ge+shi+bai;printf("%d\n",sum);return 0;}2、计算代数表达式(10 分)求:输⼊格式:输⼊⾓度x。
变量数据类型为double。
π为。
输出格式:输出y的值,精确到⼩数点后2位。
输⼊样例:输出样例:#include <>#include <>#define PIint main(){double x,y;scanf("%lf",&x);y=sqrt((sin(60*PI/180)+1)*(sin(30*PI/180)+1)/cos(x*PI/180));printf("%.2lf",y);return 0;}3、逆序的三位数(10 分)程序每次读⼊⼀个正3位数,然后输出按位逆序的数字。
注意:当输⼊的数字含有结尾的0时,输出不应带有前导的0。
⽐如输⼊700,输出应该是7。
输⼊格式:每个测试是⼀个3位的正整数。
输出格式:输出按位逆序的数。
输⼊样例:输出样例:【参考答案】#include ""int main(){ int a,ge,shi,bai,b;scanf("%d",&a);ge=a%10;shi=a/10%10;bai=a/100;b=ge*100+10*shi+bai;printf("%d\n",b);return 0;}4、求整数均值(10 分)本题要求编写程序,计算4个整数的和与平均值。
C 语言全部题目及答案Exercise1:Programming Environment and Basic Input/Output1. Write a program that prints “This is my first program!” on the screen.(a) Save this program onto your own disk with the name of e2-1a;(b) Run this program without opening Turbo C;(c) Modify this program to print “This is my second program!”, then save it ase2-1b. Please do not overwrite the first program.2. Write a program that prints the number 1 to 4 on the same line. Write the programusing the following methods:(a) Using four “printf” statemen ts.(b) Using one “printf” statement with no conversion specifier (i.e. no ‘%’).(c) Using one “printf” statement with four conversion specifiers3 .(a) Write a program that calculates and displays the number of minutes in 15 days.(b) Write a program that calculates and displays how many hours 180 minutes equal to.(c) (Optional) How about 174 minutes?ANSWERS:#include<stdio.h>int main(){printf("1"); printf("2"); printf("3"); printf("4");return 0;}return 0; }#include<stdio.h>int main(){float days,minutes; days = 15; int main() {printf("This program!");return 0;int main(){float minutes,hours;printf("The numberminutes in 15 are %f\n", minutes);printf("This program!"); int main() {return 0; }#include<stdio.h> #include<stdio.h> #include<stdio.h>of days firstmyisExercise 2: Data Types and Arithmetic Operations1. You purchase a laptop computer for $889. The sales tax rate is 6 percent. Write and execute a C program that calculates and displays the total purchase price (net price + sales tax).2 .Write a program that reads in the radius of a circle and prints the circle’s diameter, circumference and area. Use the value 3.14159 for “ ”.3 .Write a program that reads in two numbers: an account balance and an annual interest rate expressed as a percentage. Your program should then display the new balance after a year. There are no deposits or withdraws – just the interest payment. Your program should be able to reproduce the following sample run:Interest calculation program. Starting balance? 6000Annual interest rate percentage? 4.25}#include<stdio.h>int main() {printf("%d%d%d%d",1,2,3,4);return 0; }hours = minutes / 60; printf("180 minutes equal to %f hours\n", hours);return 0; }#include<stdio.h>int main() {float minutes,hours;#include<stdio.h>int main(){float net_price,sales_tax,total;net_price = 889;sales_tax = net_price * 0.06;total = net_price + sales_tax;printf("The total purchase price is %g", total);return 0;}#include<stdio.h>int main(){printf("Please input a number as radius:\n");float radius,diameter,circumference,area;scanf("%f",&radius);printf("The diameter is %g\n",diameter = radius * 2);printf("The circumference is %g\n",circumference = radius * 2 * 3.14159); printf("The area is %g\n", area = radius * radius * 3.14159);return 0;}#include<stdio.h>{float SB,percentage,NB;printf("Interest calculation program\n\nPlease enter the Starting Balance:"); scanf("%f",&SB);printf("Please enter the Annual interest rate percentage:");scanf("%f",&percentage);NB = SB * percentage / 100 + SB;printf("\nThe Balance after one year is:%g",NB);return 0;}Exercise 3: Selection structure1 . Write a C program that accepts a student’s numerical grade, converts thenumerical grade to Passed (grade is between 60-100), Failed (grade is between 0-59), or Error (grade is less than 0 or greater than 100). 2 . Write a program that asks the user to enter an integer number, then tells theuser whether it is an odd or even number. 3 . Write a program that reads in three integers and then determines and prints thelargest in the group.ANSWER: #include<stdio.h>#include<stdio.h>int main() {#include<stdio.h>int main() {int grade;printf("Please enter the grade:");scanf("%d",&grade);if (grade >= 60 && grade <= 100) printf("Passed."); else if (grade >= 0 && grade <60)#include<stdio.h>int main() {int a,b,c;printf("Please enter 3 integer numbers\n"); printf("Then I'll tell you which is thelargest\n"); scanf("%d%d%d",&a,&b,&c); if (a > b && a > c) printf("%d is the largest",a);else if (b > a && b > c) printf("%d is the largest",b); else if (c > a && c > b)int a;printf("Please enter an integer number\n");printf("Then I'll tell you whether it's an odd or even number");scanf("%d",&a);if (a%2 == 0)printf("%d is an even number",a);elseprintf("%d is a odd number",a);return 0;}Exercise 4: ‘switch’statement and simple “while” repetition statement1. Write a program that reads three integers an abbreviated date (for example: 26 12 94) andthat will print the date in full; for example: 26th December 1994. The day should be followed by an appropriate suffix, ‘st’,‘nd’,‘rd’ or ‘th’. Use at least one switch statement.2 .Write a C program that uses a while loop to calculate and print the sum of the even integersfrom 2 to 30.3. A large chemical company pays its sales staff on a commission basis. They receive £ 200 perweek plus 9% of their gross sales for that week. For example, someone who sells £ 5000 of chemicals in one week will earn £ 200 plus 9% of £5000, a total of £650. Develop a C program that will input each salesperson’s sales for the previous week, and print out their salary.Process one person’s figures at a time.Enter sales in pounds(-1to end):5000.00Salary is:650.00Enter sales in pounds(-1to end):00.00Salary is:200.00Enter sales in pounds(-1to end):1088.89Salary is:298.00Enter sales in pounds(-1to end):-1Optional:4. A mail order company sells five different products whose retail prices are shown in thefollowing table:Product Number1 2Retail Price (in pounds)2.984.503 4 59.98 4.49 6.87Write a C program that reads in a series of pairs of numbers as follows:(1). Product number(2). Quantity sold for one dayYour program should use a switch statement to help determine the retail price for each product, and should use a sentinel-controlled loop to calculate the total retail value of all products sold in a given week (7days).ANSWER:#include<stdio.h>int main(){printf("Please enter three numbers for date:");int day,month,year;scanf("%d %d %d",&day,&month,&year);if(day>31)printf("Error");else{switch (day){case 1:printf("1st");break;case 2:printf("2nd");break;case 3:printf("3rd");break;case 21:printf("21st"); break;case 22:printf("22nd"); break;case 23:printf("23rd"); break;case 31:printf("31st"); break;default:printf("%dth",day); }}switch(month){#include <stdio.h>int main(){int a,b;a=0;b=2;while (b<=30){a=a+b;b=b+2;}printf("The sum of the even integers from 2 to 30 is %d",a);return 0;}Exercise 5: ‘for’ and ‘do … while ” repetition statements1. Write a program which uses a do/while loop to print out the first 10 powers of 2 other than 0 (ie. it prints out the values of 21, 22, ..., 210). Use a for loop to do the same.2. The constant can be calculated by the infinite series:= 4 - 4/3 + 4/5 - 4/7 + 4/9 - 4/11 +....case 1: printf("January ");break;case 2: printf("February ");break;case 3: printf("March ");break;case 4: printf("April ");break;case 5: printf("May ");break;case 6: printf("June ");break;case 7: printf("July ");break;case 8: printf("August ");break;case 9: printf("September ");break;#include<stdio.h> int main() { float a,b;while (a>0 ) {printf("Enter sales in pounds (-1 to end):");scanf("%f",&a); b=200+a*0.09; if (a==-1) printf(" ");else printf("Salary is %.0f\n",b); }return 0;Write a C program that uses a do/while loop to calculate using the series. The program should ask the user how many terms in the series should be used. Thus ifthe user enters ‘3’, then the program should calcula te as being 4 - 4/3 + 4/5.Nested repetition3. Write a program that prints the following diamond shape. You may use printf statements that print either a single asterisk (*) or a single blank. Maximize your use of repetition (with nested for statements) and minimize the number of printf statements.*****************************************4. Write a program to print a table as follows:1*1= 1 2*1= 2 3*1= 3 ….9*1= 9ANSWER:#include<stdio.h> int main(){int a,b;a=0;b=1;do{a++;9*4=36 9*5=459*6=54#include <stdio.h>int main(){double c,pie,p;int a,b,d,n;printf("Enterterms:");scanf("%d",&a);printf("Pie=");9*7=63 9*8=729*9=81#include <stdio.h>int main(){int row,a,b,j;row=1;j=4;while(row<=5){for(a=j;a>=1;a=a-1) printf(" ");2*2= 43*2= 69*3=27 9*2=183*3= 9#include <stdio.h>int main () { int i, j;for (i=1; i<=9; i++) {for (j=1; j<=9; j++) if (i>=j)printf("%1d*%1d=%2d ", i, j, i*j); printf("\n"); }getchar(); return 0;int main() { int a;for(a=2;a<=1024;a=a *2) printf("%d",a); return 0; }p=p+pie;if(n>1&&n<=a) {if(n%2!=0) printf("+"); else printf("-"); }printf("4/%d",d); n++; }printf("\n=%f",p); return 0; }}row=1; j=1;while(row<=5){ for(a=1;a<=j;a=a +1) printf(" "); for(b=1;b<=9-2*j;b++) printf("*"); for(a=1;a<=j;a=a +1) printf(" "); printf("\n"); row++;Exercise 6: Simple Functions1. Write a C program that reads several numbers and uses the functionround_to_nearest to round each of these numbers to the nearest integer.Theprogram should print both the original number and the rounded number.2. Write a program that reads three pairs of numbers and adds the larger of the firstpair,the larger of the second pair and the larger of the third e a function to return the larger of each pair.3.A car park charges a£2.00minimum fee to park for up to3hours,and anadditional£0.50for each hour or part hour in excess of three hours.The maximum charge for any given24-hour period is£10.00.Assume that no car parks for more than24hours at a time.Write a C program that will calculate and print the parking charges for each of3 customers who parked their car in the car park yesterday.The program should accept as input the number of hours that each customer has parked,and output the results in a neat tabular form,along with the total receipts from the three customers:Charge2.002.50 10.0014.50The program should use the function calculate_charges to determine the charge for each customer.ANSWER: #include<stdio.h> int main() {float larger_Number(float,float); float num1,num2,total=0;int a=0;while (a<3) { void round_to_nearest(float); float num; while (5){ total=total+larger_Number(num1,num2);a=a+1; }#include<stdio.h> #include<math.h> int main() {printf("Please input a number:"); scanf("%f",&num);TOTAL Hours 29.524.0 Car 4.0 1.5 2 3 1#include <stdio.h> int main() {float calculate_charges(float);float hour1,hour2,hour3,charge1,charge2,charge3,total1=0,total2=0;printf("Please input three car's parking hours:"); scanf("%f%f%f",&hour1,&hour2,&hour3);charge1=calculate_charges(hour1); charge2=calculate_charges(hour2); charge3=calculate_charges(hour3);printf("Car Hours Charge\n"); printf("1%10.1f%10.2f\n",hour1,charge1); printf("2%10.1f%10.2f\n",hour2,charge2);void round_to_nearest(float num1) {int near_integer; intsmall_integer=floor(num1);if (num1-small_integer>=0.5) near_integer=ceil(num1); elsenear_integer=floor(num1);printf("\nThe nearest integer of the number is:%d\n",near_integer); }printf("\nThe total is %f",total);return 0; }float larger_Number(float num1,float num2) { float larger;if (num1>=num2) {printf("%f",num1); larger=num1; } else {printf("3%10.1f%10.2f\n",hour3,charge3);total1=hour1+hour2+hour3;total2=charge1+charge2+charge3;printf("TOTAL%7.2f%9.2f",total1,total2);return 0;}float calculate_charges(float hour){float charge;if (hour<=3)charge=2;if (hour>3 && hour<=19)charge=2.+0.50*(hour-3.);if (hour>19 && hour<=24)charge=10;return(charge);}Exercise 7: More Functions1.Write a program that uses sentinel-controlled repetition to take an integer as input,and passes it to a function even which uses the modulus operator to determine if the integer is even. The function even should return 1 if the integer is even, and0 if it is not.base exponentThe program should take the value returned by the function even and use it to print out a message announcing whether or not the integer was even.2.Write a C program that uses the function integerPower1(base,exponent)to return the value of:base exponentso that, for example, integerPower1(3, 4) gives the value 3 * 3 * 3 * 3.Assume that exponent is a positive, non-zero integer, and base is an integer.The function should use a for loop, and make no calls to any math library functions.3. Write a C program that uses the recursive function integerPower2(base,exponent) to return the value of:base exponentso that, for example, integerPower2(3, 4) gives the value 3 * 3 * 3 * 3. Assume that exponent is a positive, non-zero integer, and base is an integer.The function should make no calls to any math library functions.(Hint:the recursive step will use the relationship:base exponent=base.base exponent-1and the base case will be when exponent is1since:base1=base.)ANSWER:#include<stdio.h>int main(){int a,b;int judge(int);void judge1(int);printf("Please enter a number");scanf("%d",&a);while(a>=-1){b=judge(a);judge1(b);printf("Please evter a number");scanf("%d",&a);}return 0;}int judge(int x){if (x%2!=0)return (0);elsereturn (1);}void judge1(int x){if (x==1)printf("It's even\n"); elseprintf("It's odd\n");#include<stdio.h>int main(){int integerPower2(int,int);int base,exponent,result;printf("This program cancalculate the power\n");printf("Enter a integer basenumber:\n");scanf("%d",&base);printf("Enter a non-zerointeger number as the exponent:\n");scanf("%d",&exponent);result=integerPower2(base,expo nent);printf("The power is:%d",result); return 0;}int integerPower2(int x,int y){if(y==1)return (x);elsereturn (x*integerPower2(x,y-1)); }#include <stdio.h>int main(){int integerPower1(int,int);int base,exponent,answer;printf("Let us calculate the power\n");} printf("Please enter a integer base number:\n");scanf("%d",&base);printf("Please enter a non-zero integer number asthe exponent:\n");scanf("%d",&exponent);answer=integerPower1(base,exponent);printf("So the power is:%d",answer);return 0;}int integerPower1(int x,int y){int i,a;Exercise 08: Arrays1.Write a program that reads ten numbers supplied by the user into a singlesubscripted array,and then prints out the average of them.2. Write a program that reads ten numbers supplied by the user into a 2 by 5 array,and then prints out the maximum and minimum values held in:(a)each row(2rows)(b) the whole array3 .Use a single-subscripted array to solve the following problem. Read in 20numbers,each of which is between10and100,inclusive.As each number is read, print it only if it is not a duplicate of a number already read.Prepare for the “worst case”in which all 20 numbers are different. Use the smallest possible array to solve this problem.#include<stdio.h>int main(){#define MAXGRADES 10 int grades[MAXGRADES]; int i, total = 0;#include<stdio.h>int main(){#define MAXNUM 5int number[MAXNUM]; int i,j,a;ANSWER: #include<stdio.h> int main() {#define NUMROWS 2 #define NUMCOLS 5int number[NUMROWS][NUMCOLS]; int i,j,max1,max2,min1,min2;for (i=0;i<NUMROWS;i++){ printf("Please input 5 numbers with space between each other:\n"); for (j=0;j<NUMCOLS;j++) scanf("%d",&number[i][j]); }max1=number[0][0]; min1=number[0][0]; max2=number[1][0];{ printf("Enter a number:"); scanf("%d",&grades[i]); }printf("\nThe average of the numbers\n"); for(i=0;i<MAXGRADES;i++) { printf("%d",grades[i]); total+=grades[i]; }average = total/10.0;for(i=0;i<MAXNUM;i++) scanf("%d",&number[i]);a=0;for(i=0;i<MAXNUM;i++) { for(j=0;j<i;j++) {if(number[i]==number[j])a++;}min2=number[1][0];for(j=0;j<NUMCOLS;j++) { if(number[0][j]>=max1) max1=number[0][j];if(number[0][j]<=min1)min1=number[0][j];if(number[1][j]>=max2)max2=number[1][j];if(number[1][j]<=min2)min2=number[1][j];}printf("The max of the first row is %d\n",max1);printf("The min of the first row is %d\n",min1);printf("The max of the second row is %d\n",max2);printf("The min of the second row is %d\n",min2);printf("The max of two rows is ");if (max1>=max2)printf("%d\n",max1);else printf("%d\n",max2);printf("The min of two rows is ");if (min1<=min2)printf("%d\n",min1);else printf("%d\n",min2);return 0;}Exercise 9: More Arrays1. Write a program that enters 5 names of towns and their respective distance (aninteger) from London in miles. The program will print of the names of the towns that are less than 100 miles from London. Use arrays and character strings to implement your program.2. Write a program that prompts the user to type in four character strings, placesthese in an array of strings, and then prints out: (e.g. I am Peter Pan)(i) The four strings in reverse order. (e.g. Pan Peter am I)(ii) The four strings in the original order, but with each string backwards. (e.g. I ma reteP naP)(iii) The four strings in reverse order with each string backwards. (e.g. naP reteP ma I)#include<stdio.h>int main(){char character[5][20];int integer[5];int i;for(i=0;i<5;i++){ printf("Please enter a name of a town:\n");scanf("%s",character[i]);printf("Enter its distance from London in miles:\n");scanf("%d",&integer[i]);}printf("The towns that are less than 100 miles from London are:\n"); for(i=0;i<5;i++){if(integer[i]<100)printf("%s",character[i]);}return 0;}Exercise 10: Pointers1. Write a program that reads 5 integers into an array, and then uses four differentmethods of accessing the members of an array to print them out in reverse order.//Pan Peter am I #include<stdio.h> int main() {char four[4][81]; int i;printf("Please input four words:\n");for(i=0;i<4;i++) scanf("%s",four[i]);printf("The four strings in reverse order is :\n"); for(i=3;i>=0;i--) { printf("%s",four[i]);//naP reteP ma I #include <stdio.h> int main() {char four[4][81]; int i,j;printf("Please input four words:\n"); for(i=0;i<4;i++)scanf("%s",four[i]); printf("The four strings are:\n"); for(i=3;i>=0;i--) {for(j=0;four[i][j]!='\0';j++); for(j=j-1;j>=0;j--) {2. Write a program that reads 8 floats into an array and then prints out the second,fourth, sixth and eighth members of the array, and the sum of the first, third, fifth and seventh, using pointers to access the members of the array.3. (Optional) Write a program that use a SINGLE FUNCTION (用一个函数)tofind and return simultaneously both the lowest and highest values in an array of type int. Suppose the size of the array is 6.ANSWER:#include<stdio.h>int main(){int num1[5],i;printf("Please input 5 numbers:\n");for (i=0;i<5;i++)scanf("%d",&num1[i]);//the first wayprintf("\nPrint them out in reverse order in the first way:\n");for (i=4;i>=0;i--)printf("%d",num1[i]);//the second wayprintf("\nPrint them out in reverse order in the second way:\n");int *num2;num2 = &num1[0];for (i=4;i>=0;i--)printf("%d",*(num2+i));//the third wayprintf("\nPrint them out in reverse order in the third way:\n");for(i=4;i>=0;i--)printf("%d",*(num1+i));//the fourth wayprintf("\nPrint them out in reverse order in the fourth way:\n");int *num4;num4 = &num1[4];for (i=0;i<5;i++)printf("%d",*(num4-i));return 0;}#include<stdio.h>int main(){float num[8];int i;printf("Please input 8 floats:\n");for (i=0;i<8;i++)scanf("%f",&num[i]);//first, print out the second,fourth,sixth and eighthmembers of the arrayfor (i=1;i<8;i=i+2)printf("%f",*(num+i));//second, print out the sum of thefirst,third,fifthand seventhfloat total;for (i=0;i<8;i=i+2)total = total+*(num+i); #include<stdio.h>void SingleFunction(int *,int *); int main(){int num[6];int i;printf("Please input 6numbers:\n"); for (i=0;i<6;i++)scanf("%d",&num[i]);SingleFunction(num,num); return 0;}void SingleFunction(int *max,int *min) {int i,maxnum,minnum; maxnum = *max++;minnum = *min++;for(i=-1;i<5;i++)。