全国计算机等考二级C语言:程序设计实战(8)_第1页
全国计算机等考二级C语言:程序设计实战(8)_第2页
全国计算机等考二级C语言:程序设计实战(8)_第3页
全国计算机等考二级C语言:程序设计实战(8)_第4页
免费预览已结束,剩余7页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、姓名:_ 班级:_ 学号:_-密-封 -线- 全国计算机等考二级c语言:程序设计实战(8)考试时间:120分钟 考试总分:100分题号一二三四五总分分数遵守考场纪律,维护知识尊严,杜绝违纪行为,确保考试结果公正。【程序31】题目:请输入星期几的第一个字母来判断一下是星期几,如果第一个字母一样,则继续判断第二个字母。1.程序分析:用情况语句比较好,如果第一个字母一样,则判断用情况语句或if语句判断第二个字母。2.程序源代码:#include “stdio.h”#include “conio.h”void main()char letter;printf(“please input the fir

2、st letter of somedayn”);while(lettergetch()!y)/*当所按字母为y时才结束*/switch (letter)case s:printf(“please input second lettern”);if(lettergetch()a)printf(“saturdayn”);else if (lettergetch()u)printf(“sundayn”);else printf(“data errorn”);break;case f:printf(“fridayn”);break;case m:printf(“mondayn”);break;case

3、 t:printf(“please input second lettern”);if(lettergetch()u)printf(“tuesdayn”);else if (lettergetch()h)printf(“thursdayn”);else printf(“data errorn”);break;case w:printf(“wednesdayn”);break;default: printf(“data errorn”);getch();. 【程序32】题目:press any key to change color, do you want to try it. please

4、hurry up!1.程序分析:2.程序源代码:#include “l. 【程序33】题目:学习gotoxy()与clrscr()函数1.程序分析:2.程序源代码:#include “conio.h”#include “stdio.h”void main(void)clrscr();/*清屏函数*/textbackground(2);gotoxy(1, 5);/*定位函数*/cprintf(“output at row 5 column 1n”);textbackground(3);gotoxy(20, 10);cprintf(“output at row 10 column 20n”);ge

5、tch();. 【程序34】题目:练习函数调用1. 程序分析:2.程序源代码:#include “stdio.h”#include “conio.h”void hello_world(void)printf(“hello, world!n”);void three_hellos(void)int counter;for (counter 1; counter 3; counter+)hello_world();/*调用此函数*/void main(void)three_hellos();/*调用此函数*/getch();. 【程序35】题目:文本颜色设置1.程序分析:2.程序源代码:#incl

6、ude “stdio.h”#include “conio.h”void main(void)int color;for (color 1; color 16; color+)textcolor(color);/*设置文本颜色*/cprintf(“this is color %drn”, color);textcolor(128 + 15);cprintf(“this is blinkingrn”);getch();. 【程序36】题目:求100之内的素数1.程序分析:2.程序源代码:#include “stdio.h”#include “math.h”#define n 101main()in

7、t i,j,line,an;for(i2;ifor(i2;ifor(ji+1;jif(ai!0printf(“n”);for(i2,line0;iif(ai!0)printf(“%5d”,ai);line+;if(line10)printf(“n”);line0;getch();. 【程序37】题目:对10个数进行排序1.程序分析:可以利用选择法,即从后9个比较过程中,选择一个最小的与第一个元素交换,下次类推,即用第二个元素与后8个进行比较,并进行交换。2.程序源代码:#include “stdio.h”#include “conio.h”#define n 10main()int i,j,m

8、in,tem,an;/*input data*/printf(“please input ten num:n”);for(i0;iprintf(“a%d”,i);scanf(“%d”,printf(“n”);for(i0;iprintf(“%5d”,ai);printf(“n”);/*sort ten num*/for(i0;imini;for(ji+1;jif(aminaj)minj;temai;aiamin;amintem;/*output data*/printf(“after sorted n”);for(i0;iprintf(“%5d”,ai);getch();. 【程序38】题目:

9、求一个3*3矩阵对角线元素之和1.程序分析:利用双重for循环控制输入二维数组,再将aii累加后输出。2.程序源代码:#include “stdio.h”#include “conio.h”/* 如果使用的是tc系列编译器则可能需要添加下句 */static void dummyfloat(float *x) float y; dummyfloat(main()float a33,sum0;int i,j;printf(“please input rectangle element:n”);for(i0;i3;i+)for(j0;j3;j+)scanf(“%f”,for(i0;i3;i+)su

10、msum+aii;printf(“duijiaoxian he is %6.2f”,sum);getch();. 【程序39】题目:有一个已经排好序的数组。现输入一个数,要求按原来的规律将它插入数组中。1. 程序分析:首先判断此数是否大于最后一个数,然后再考虑插入中间的数的情况,插入后此元素之后的数,依次后移一个位置。2.程序源代码:#include “stdio.h”#include “conio.h”main()int a111,4,6,9,13,16,19,28,40,100;int temp1,temp2,number,end,i,j;printf(“original array is

11、:n”);for(i0;i10;i+)printf(“%5d”,ai);printf(“n”);printf(“insert a new number:”);scanf(“%d”,enda9;if(numberend)a10number;elsefor(i0;i10;i+)if(ainumber)temp1ai;ainumber;for(ji+1;j11;j+)temp2aj;ajtemp1;temp1temp2;break;for(i0;i11;i+)printf(“%6d”,ai);getch();. 【程序40】题目:将一个数组逆序输出。1.程序分析:用第一个与最后一个交换。2.程序源代码:#include “stdio.h”#include “conio.h”#define n 5main()int an9,6,5,

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论