高程C编程题库

上传人:小****克 文档编号:211979538 上传时间:2021-11-18 格式:PDF 页数:21 大小:122.88KB
返回 下载 相关 举报
高程C编程题库_第1页
第1页 / 共21页
高程C编程题库_第2页
第2页 / 共21页
高程C编程题库_第3页
第3页 / 共21页
高程C编程题库_第4页
第4页 / 共21页
高程C编程题库_第5页
第5页 / 共21页
点击查看更多>>
资源描述

《高程C编程题库》由会员分享,可在线阅读,更多相关《高程C编程题库(21页珍藏版)》请在金锄头文库上搜索。

1、1. 从键盘输入3 个整数,求其中的最大数和最小数,并输出结果。# include stdio.h void main() int x, y, z, max, min; printf(Please input three integer number:); scanf(%d %d %d, &x, &y, &z); min = max = x; if(x=y & y=z) printf(x = y = z, max=min=%dn, max); else if (ymax) max = y; if (zmax) max = z; if (ymin) min = y; if (zmin) min

2、= z; printf(max=%d, min=%dn, max, min); 2. 从键盘上输入一个3*3 的整数矩阵,求其各行的平均值并输出,输出时保留两位小数。#include void main() int a33,b3=0; int i,j; printf( 请输入一个三行三列的整数矩阵:n); for(i=0;i3;i+) for(j=0;j3;j+) scanf(%d,&aij); for(i=0;i3;i+) for(j=0;j3;j+) bi=bi+aij; for(i=0;i3;i+) printf( 该矩阵第 %d 行元素的平均值是:%.2fn,i+1,bi/3.0);

3、3. 输出 x2的值, x 取值从 0 到 10。#include stdio.h void main() int x; for(x=0; x=10; x+) printf(square(%d)=%dn, x, x*x); 4. 从键盘上输入一个3*4 的整数矩阵,要求输出其最大元素的值,以及它的行号和列号。#include stdio.h void main() int a34, max, i, j, row, colum; printf( 请输入 3*4 的整数矩阵:n); for(i=0;i3;i+) for(j=0;j4;j+) scanf(%d,&aij); max=a00; row

4、=0; colum=0; for(i=0;i3;i+) for(j=0;jmax) max=aij; row=i; colum=j; printf(max=%d, row=%d, colum=%d n,max, row, colum); 5. 任意输入10 个整数,打印出10 个数中的最大值。#include void main() int n, max, i; scanf(%d, &max); for (i = 1; i max) max = n; printf(max=%d, max); 6. 编写一个函数根据以下公式计算s,计算结果作为函数值返回;n 通过形参传入。 s= #includ

5、e double f1(int n); void main() int n=1; printf(Input the value of nn); scanf(%d,&n); printf(%lf,f1(n); double f1(int n) int i; double term,s=0; for(i=1;i=n;i+) term=1.0/(2*i-1); s+=term; return(s); 7. 输出 1000 年(包括1000 年)到 1999 年之间的所有闰年,要求每三个一行,分行输出。#include void main() int i=0; int year,leap; for(y

6、ear=1000;year2000;year+) if (year%4=0) if(year%100=0) if(year%400=0) leap=1; else leap=0; else leap=1; else leap=0; if(leap) i+; printf(%dt,year); if (i%3=0) printf(n); 8. 编写程序打印所有的“水仙花数”。 “水仙花数”指一个三位数,其各位数字立方和等于该数本身,例如153 是一个“水仙花数” ,因为 153 111 333555。#include void main() int i,j,k,n; printf(result

7、is:); for(n=100;n1000;n+) i=n/100; j=(n-i*100)/10; k=n%10; if(n=i*i*i+j*j*j+k*k*k) printf(%d ,n); printf(n); 9. 编写一个程序,输入一个3 位数的正整数,然后反向输出对应的数。如:123,则输出321。#include void main() int i,s=0,j; scanf(%d,&i); if(i=100&i=999) j=i%10; s=s+j; j=(i-j)/10%10; s=s*10+j; j=i/100; s=s*10+j; printf(the inverse nu

8、mber is %d,s); else printf(input erroe!); 10. 将十个整数输入数组,求出其平均值并输出。#include void main() int a10,i; float ave; for(i=0;i10;i+) scanf(%d,&ai); for(i=1;i10;i+) ave=ave+ai; ave=ave/10.0; printf(ave=%f,ave); 11. 从键盘输入10 名学生的 C语言成绩存入一维数组内,编写程序计算10 名学生的最高分、平均分和及格人数。#include void main() int i,score10,max,min

9、; float ave; for(i=0;i10;i+) scanf(%d,&scorei); max=score0; min=score0; ave=score0; for(i=1;imax) max=scorei; if(scoreimin) min=scorei; ave=ave+scorei; ave=ave/10.0; printf(max=%d,min=%d,ave=%f,max,min,ave); 12. 编写一个程序,判断用户输入的字符是否是数字,若是数字,则输出“a numerical character” , 否则输出“ other character” 。#include

10、 void main() char ch; ch=getchar(); if(ch=0&ch=9) printf(a numerical character); else printf(other character); 13. 利用函数将给定的3 3 二维数组转置。#include stdio.h void convert(int array33) int i,j,k; for(i=0;i3;i+) for(j=i+1;j3;j+) k=arrayij; arrayij=arrayji; arrayji=k; void main() int i,j; int a33=1,2,3,4,5,6,

11、7,8,9; printf( 转换前 :n); for(i=0;i3;i+) for(j=0;j3;j+) printf(t%d,aij); printf(n); convert(a); printf(n 转换后 :n); for(i=0;i3;i+) for(j=0;j3;j+) printf(t%d,aij); printf(n); 14. 编程输入a、b、c 的值后,输出一元二次方程ax2+bx+c=0 的解。#include #include void main( ) float a, b, c,d, x1, x2; printf(input a,b,c: ); scanf(%f%f%

12、f, &a, &b, &c); d = sqrt(b * b - 4 * a *c); x1 = (-b + d) / (2 * a); x2 = (-b - d) / (2 * a); printf(x1 = %.2f x2 = %.2fn, x1, x2); 15. 从键盘上输入任意两个数和一个运算符(+、- 、 *、/ ) ,根据输入的运算符对两个数计算,并输出结果。#include void main() float a, b; int tag = 0; char ch; float result; printf(input two number: ); scanf(%f%f, &a,

13、 &b); fflush(stdin); printf(input arithmetic lable(+ - * /): ); scanf(%c, &ch); switch(ch) case +: result = a + b; break; case -: result = a - b; break; case *: result = a * b; break; case /: if (!b) printf(divisor is zero!n); tag = 1; else result = a / b; break; default: printf(illegal arithmetic l

14、ablen); tag = 1; if (!tag) printf(%.2f %c %.2f = %.2fn, a, ch, b, result); 16. 有一分数序列:2/1 ,3/2 ,5/3 ,8/5 ,13/8 ,21/13.求出这个数列的前20 项之和。#include stdio.h void main() int n,t,number=20; float a=2,b=1,s=0; for(n=1;n=number;n+) s=s+a/b; t=a;a=a+b;b=t; printf(sum is %9.6fn,s); 17. 使用循环结构编写程序,打印出如下图案* * * #i

15、nclude stdio.h void main() int i,j,k; for(i=1;i=3;i+) for(j=1;j=3-i;j+) printf( ); for(k=1;k=2*i-1;k+) printf(*); printf(n); 18. 用冒泡排序法将10 个整数由大到小排序。#include void main( ) int a10, i, j, t; printf (input %d numbers: n, 10); for (i = 0; i 10; i+) scanf (%d, &ai); for (i = 0; i 9; i+) for (j = 0; j 9 -

16、 i; j+) if (aj aj+1) t = aj; aj = aj+1; aj+1 = t; printf (the sorted numbers:n); for (i = 0; i 10; i+) printf (%d , ai); 19. 输入任意正整数,编程判断该数是否为回文数( 回文数是指从左到右读与从右到左读一样,如 12321) 。#include void main( ) int n, m = 0, s, r; printf (Input data is: ); scanf (%d, &n); s = n; while (s != 0) r = s % 10; m = 10 * m + r; s = s / 10; if (m = n) printf (yesn); else printf (non); 20. 输入一字符串, 检查是否回文(回文是指正反序相同,如,LeveL) ,若是则输出 “Yes” ,否则输出“ No” 。#include #include void main() int i,j,tag=0; char ch50; printf(Please

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 工作范文

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号