下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、1. 输入一个不超过五位的正整数, 输出其逆数。例如输入 12345, 输出应为 54321。#include "stdio.h"main()long n;int ww,qw,bw,sw,gw; printf("Please input:n"); scanf("%ld",&n); while(n<=0|n>99999)printf("nThe number is too little or too large.Retry please!n");scanf("%ld",&
2、;n); if(n>=10000&&n<=99999)ww=n/10000;qw=n/1000%10;bw=n/100%10;sw=n/10%10;gw=n%10;printf("The old number is:%ldn",n);printf("The new number is:%d%d%d%d%dn",gw,sw,bw,qw,ww );else if(n>=1000&&n<=9999)qw=n/1000; bw=n/100%10; sw=n/10%10; gw=n%10;printf(&qu
3、ot;Theoldnumber is:%ldn",n);printf("Thenewnumber is:%d%d%d%dn",gw,sw,bw,qw);else if(n>=100&&n<=999) bw=n/100; sw=n/10%10; gw=n%10; printf("The old number is:%ldn",n);printf("The new number is:%d%d%dn",gw,sw,bw);else if(n>=10&&n<=99)sw=n/
4、10;gw=n%10;printf("The old number is:%ldn",n);printf("The new number is:%d%dn",gw,sw);else printf("The old number equals the new number:%ld",n);2. 计算1+2+3+n的值,n是从键 盘输入的自然数。/* Note:Your choice is C IDE */#include "stdio.h"main()int n,i;long sum=0;printf("1
5、+2+3+nn");printf("Please input n:n"); scanf("%d",&n);for(i=1;i<=n;i+)sum+=i;printf("sum=%ld",sum);3. 从终端(键盘)读入 20 个数据 到数组中,统计其中正数的个 数,并计算这些正数之和。 、/* Note:Your choice is C IDE */#include "stdio.h"#define N 20main()int aN,i,sum=0,count=0;printf("
6、;Pleaseinputnumbers :n");for(i=0;i<N;i+)scanf("%d",&ai);if(ai>0) sum+=ai;count+; printf("count=%d,sum=%d",co unt,sum);4. 从终端(键盘)将 5 个整数输入 到数组 a 中,然后将 a 逆序复制 到数组 b 中,并输出 b 中各元素 的值。/* Note:Your choice is C IDE */#include "stdio.h"#define N 5main() int aN,bN
7、,i;printf("Please input numbers:n");for(i=0;i<N;i+) scanf("%d",&ai);bN-i-1=ai;printf("nThe old numbers are:n");for(i=0;i<N;i+) printf("%-4d",ai);printf("nThe new numbers are:n");for(i=0;i<N;i+) printf("%-4d",bi);5. 要将五张 100 元的大
8、钞票, 换成 等值的 50 元, 20 元, 10 元, 5 元一张的小钞票, 每种面值至少 1 张,编程输出所有可能的换法, 程序应适当考虑减少重复次数。/* Note:Your choice is C IDE */#include "stdio.h"main() int i,j,k,n;for(i=1;i<=10;i+) for(j=1;j<=25;j+) for(k=1;k<=50;k+)for(n=1;n<=100;n+)if(i*50+j*20+k*10+n*5=500)printf("num50=%d,num20=%d,n um
9、10=%d,num5=%dn",i,j,k,n);6. 求n以内(不包括n)同时能被 3和 7整除的所有自然数之和的 平方根 s, n 从键盘输入。例如 若 n 为 1000 时,函数值应为: s=153.909064 。/* Note:Your choice is C IDE */#include "stdio.h"#include "math.h"main() int n,s,i;float sum=0; printf("Please input n:n");scanf("%d",&n); w
10、hile(n<=0) printf("nError input.Retry please:n");scanf("%d",&n);for(i=1;i<n;i+)if(i%3=0&&i%7=0)sum+=i;printf("Thenumberis:%4.2f",sqrt(sum);7. 一辆卡车违反交通规则, 撞人后 逃跑。现场有三人目击事件,但 都没有记住车号, 只记下车号的 一些特征。甲说:牌照的前两位 数字是相同的;乙说:牌照的后 两位数字是相同的, 但与前两位 不同;丙是数学家,他说:四位 的车
11、号刚好是一个整数的平方。 请根据以上线索找出车号。/* Note:Your choice is C IDE */#include "stdio.h"#include "math.h" main()int i,qw,bw,sw,gw;for(i=1122;i<=9988;i+) if(sqrt(i)!=(int)sqrt(i) continue;qw=i/1000; bw=i/100%10; sw=i/10%10;gw=i%10; if(qw=bw&&sw=gw)printf("nThenumberis:%dn",
12、i);break;8. 输入 110 之间的一个数字,输 出它对应的英文单词。/* Note:Your choice is C IDE */ #include "stdio.h" main()int n;printf("Please input n:n"); scanf("%d",&n);while(n<1|n>10)printf("Errorinput!Retry please:n"); scanf("%d",&n);switch(n)case1:printf(&q
13、uot;One!");break;case2:printf("Two!");break;case3:printf("Three!");break;case4:printf("Four!");break;case5:printf("Five!");break;case6:printf("Six!");break;case7:printf("Seven!");break;case8:printf("Eight!");break;case9:print
14、f("Nine!");break;case10:printf("Ten!");break;9. 个位数为 6 且能被 3整除但不能 被 5 整除的三位自然数共有多少 个,分别是哪些?/* Note:Your choice is C IDE */ #include "stdio.h" main()int i,count=0;for(i=106;i<596;i=i+10)if(i%3=0&&i%5!=0)printf("%-4d",i);count+;printf("count=%-4d
15、",count);10. 用自然语言描述程序逻辑如下, 试写程序。 设置环境; 定义变量i、j、s,以及用 于放置结果的变量 sum并令sum初值为 0;i=1;如果i < 100,则转,否则转;令s=0,求前i个自然数之和,并放于变量 s 之中; sum=sum+s; i 增加 1 ,转; 输出和sum,结束。/* Note:Your choice is C IDE*/#include "stdio.h"main()int i,j;long s=0,sum=0;printf("1+1+2+1+2+3+1+2+3+4+1+2+3+.+nn"
16、;);i=1;while(i<=3)s+=i;sum+=s;i+;printf("sum=%ld",sum);11. 用自然语言描述的程序逻辑为: 设置环境; 定 义 变 量 i 、 flag 和password ,并令 flag=0 , i=0 ; 用户回答口令,将其赋于password 变量; 口令正确? 如果是 ,则flag=1,转。否则转; 回答三次口令了吗?如果 没有,计数器加1后(i+ ),转, 否则转; 根据 flag 之值输出相应信 息。/* Note:Your choice is C IDE*/#include "stdio.h"
17、#include "string.h"#define N 6main()int i=0,flag=0;char passwordN;printf("Thepasswordis:123456n");while(i<3)gets(password);if(strlen(password)!=6) printf("The string length is wrong!Retry please!n");i+;continue;if(strcmp("123456",pass word)=0)flag=1;break;
18、else printf("Wrong input!Retryplease!n");i+;if(flag=1)printf("Right password!n");elseprintf("Wrongpassword!n");12. 用自然语言描述的程序逻辑如 下: 设置环境; 定义变量 digit 、x、y 分别 表示原始数、原始数的个位数和逆 数; 输入原始正整数 x ; 从 x 中分解出个位数字 digit ; 合并个位 digit 至逆数 y 中; 原始数 x 缩小 10 倍: x=x/10 ; 如果x非零,则转; 输出逆数 y
19、,结束/* Note:Your choice is C IDE*/#include "stdio.h"main()long digit,x,y;/* 个 位 数、原始数、逆数 */printf("Please input the old number:n");scanf("%ld",&x);digit=x%10;y=digit;while(x!=0)x=x/10;digit=x%10;y=y*10+digit; printf("x=%ld,y=%ld",x, y/10);13. 输入某三角形的三个边的长度,
20、 判断出这是个什么三角形(等 腰、等边、任意,或不能构成) 。/* Note:Your choice is C IDE */#include "stdio.h"main()float a,b,c,flag;/*flag=0 不 能, flag=1 等边 ,flag=2 等腰, flag=3 任意 */printf("Pleaseinputangles:n");scanf("%f,%f,%f",&a,&b,&c);if(a+b<=c|a+c<=b|b+c<=a)flag=0;else if(a=
21、b&&b=c)flag=1;elseif(a=b|b=c|c=a)flag=2;else flag=3;if(flag=0) printf("nCan not!n");if(flag=1) printf("nDengBian.n");if(flag=2) printf("nDengYao.n");if(flag=3) printf("nPu tong.n");14. 输入 10 个数,分别统计其中正 数、负数、零的个数。#include "stdio.h" #define N 1
22、0 main() int aN;int i,count1=0,count2=0,count3=0;/* count1 记录正数个数, count2 记录 负数个数, count3 记录 0 的个数 */printf("Please input numbers:n");for(i=0;i<N;i+) scanf("%d",&ai); if(ai>0)count1+;if(ai<0)count2+;if(ai=0)count3+; printf("count1=%-4d,count2=%-4d ,count3=%-4d&q
23、uot;,count1,count2,cou nt3);15. 先随机产生 N 个三位自然数输 出,然后再输出其中同时是 3、5、 7 倍数的数。(设 N 为 100)/* Note:Your choice is C IDE */#include "stdio.h"#define N 100#include <time.h>#include <stdlib.h> main() int aN,i;printf("Please input numbers:n");randomize();for(i=0;i<N;i+) ai=ra
24、ndom(900)+100;printf("%-4d",ai);n");printf("n3,5,7:n");for(i=0;i<N;i+)if(ai%3=0&&ai%5=0&&a i%7=0)printf("%-4d",ai);16. 用 for 编程找出 100200 中的完 全平方数。#include "stdio.h"#include "math.h"main()int i;for(i=100;i<=200;i+)if(sqrt(i)
25、=i%100) printf("%-4d",i);17. 从终端输入三个正实数, 判断这 三个数能否构成直角三角形 。#include "stdio.h"main()float a,b,c,flag;/*flag=0 不 能, flag=1 能 */printf("Please input angles:n");scanf("%f,%f,%f",&a,&b,&c);while(a<=0|b<=0|c<=0) printf("Wrong input!Retry pl
26、ease:n");scanf("%d,%d,%d",&a,&b,&c); if(a+b<=c|b+c<=a|a+c<=b)flag=0;else if(a*a=b*b+c*c|b*b=a*a+c*c| c*c=a*a+b*b)flag=1;else flag=0;if(flag=1)printf("nCan!");else printf("nCan not!");18. 输入一行字符, 统计其中有多少 个字母(包括大写字母和小写字 母)。/* Note:Your choice is
27、C IDE */ #include "stdio.h" #define N 10 #include "stdlib.h" #include "ctype.h" #include "string.h" main()char cN;int i,count=0; gets(c);i=0; while(i!=strlen(c)if(isupper(ci)|islower(ci)count+; i+;printf("count=%-4d",count); getch();19. 输入一个字串, 判断它是否
28、是对 称串。女口” abcdcba”是对称串,” 123456789”不是。/* Note:Your choice is C IDE */ #include "stdio.h" #include "string.h" #include "ctype.h" #include "stdlib.h" #define N 10 main() char aN,bN,i;printf("Please input the string:n");gets(a); if(strlen(a)>N) print
29、f("Wrong input!Retry please!n");gets(a);strcpy(b,a); strrev(a);if(strcmp(a,b)=0)printf("nYes!n");else printf("nNo!n");20. 随机产生 N 个大写字母输出, 然 后统计其中共有多少个元音字 符。(设N为200)/* Note:Your choice is CIDE */ #include "stdio.h"#include <stdlib.h>#include <time.h>
30、; #define N 200 main()int cN,i,count=0; randomize(); for(i=0;i<N;i+) ci=random(27)+65; printf(" %c",ci); if(ci='A'|ci='E'|ci='I'|ci='O'|ci='U') count+;printf("nn");printf("ncount=%-4d",count); 找出三位自然数中的所有素数, 要 求判断 x 素 数用自 定义 函数
31、 data(x) 实现。#include "stdio.h"int data(int x); main() int i,flag=0;/*1 是, 0 否 */ for(i=101;i<=999;i+) flag=data(i);if(flag=1)printf("%-4d",i);int data(int x)int i;for(i=2;i<x/2;i+) if(x%i=0) return 0;if(i=x/2)return 1;else return 0;21. 输出 n 行由“ #”组成的矩形, 每行“#”的个数为m个,其中n、 m由终
32、端(键盘)输入。要求输 出m个“ #”功能由函数 satr(m) 函数实现。#include "stdio.h"void satr(int m);main() int i,n,m;printf("Pleaseinputn&m:n");printf("n="); scanf("%d",&n);printf("m="); scanf("%d",&m);printf("nn");for(i=1;i<=n;i+)satr(m);pri
33、ntf("n");void satr(int m) int i;for(i=1;i<=m;i+)printf("#");222. 若 ax +bx+c=0 有实根,则求之。 #include "stdio.h" #include "math.h"main()int a,b,c;float derta,x1,x2;printf("Please input a,b,c:n");printf("a="); scanf("%d",&a);printf
34、("b=");scanf("%d",&b); printf("c="); scanf("%d",&c);derta=b*b-4*a*c;if(derta<0)printf("NO!n");if(derta=0) printf("One!n"); x1=-b/(2*a); x2=x1;printf("x=%-4.2f",x1);if(derta>0) printf("Two!n");x1=(-b+sqrt(de
35、rta)/(2*a);x2=(-b-sqrt(derta)/(2*a); printf("x1=%-4.2f,x2=%-4.2f",x1,x2);23. 从键盘输入两个字串, 判断它们 是否相同。#include "stdio.h"#include "string.h"#define N 20main()char c1N,c2N;printf("Please input two string below:n");gets(c1);gets(c2);printf("-n");printf(&quo
36、t;The answer is:"); if(strcmp(c1,c2)=0) printf("Equal!n");elseprintf("Notequal!n");24. 从键盘输入两个字串, 输出其中 较短的那个字串, 并输出它的长 度。#define N 20#include "stdio.h"#include "string.h"main()char c1N,c2N;printf("Please input two string below:n");gets(c1);gets(
37、c2);printf("-n");printf("The answer is:"); if(strlen(c1)=strlen(c2) puts(c1);puts(c2);printf("The lengthis:%dn",strlen(c1);if(strlen(c1)<strlen(c2) puts(c1);printf("The length is:%dn",strlen(c1);if(strlen(c1)>strlen(c2)puts(c2);printf("The length is
38、:%dn",strlen(c2);25. 从键盘输入长度不等的两个字 串,将短串连接于长串之后输 出。#include "stdio.h"#include "string.h"#define N 20main()char c1N,c2N;printf("Please input two string below:n");gets(c1);gets(c2);while(strlen(c1)=strlen(c2)printf("Wrong input!Retry please:n");gets(c1);get
39、s(c2);printf("n");printf("The answer is:"); if(strlen(c1)<strlen(c2) puts(strcat(c2,c1); if(strlen(c1)>strlen(c2) puts(strcat(c1,c2);26. 从键盘输入长度不等的两个字 串,将长串连接于短串之后输出#include "stdio.h"#include "string.h"#define N 20main() char c1N,c2N;printf("Please
40、input two string below:n");gets(c1);gets(c2); while(strlen(c1)=strlen(c2 ) printf("Wrong input!Retry please:n");gets(c1);gets(c2);printf("-n");printf("The answer is:");if(strlen(c1)<strlen(c2) puts(strcat(c1,c2);if(strlen(c1)>strlen(c2) puts(strcat(c2,c1);27.
41、 随机产生 N 个两位自然数, 降序排列后输出。(设N为20)#include "stdio.h"#include "stdlib.h"#include "time.h"#define N 20main() int aN,i,j,temp;randomize();for(i=0;i<N;i+) ai=random(900)+100;for(i=0;i<N-1;i+) for(j=i+1;j<N;j+) if(aj>ai) temp=ai; ai=aj; aj=temp;for(i=0;i<N;i+) pr
42、intf("%-4d",ai);28. 从键盘输入两个字串, 输出其中 较长的那个字串, 并输出它的长 度。#define N 20#include "stdio.h" #include "string.h" main()char c1N,c2N; printf("Please input two string below:n");gets(c1); gets(c2); printf("-n"); printf("The answer is:"); if(strlen(c1)
43、=strlen(c2) puts(c1);puts(c2); printf("The length is:%dn",strlen(c1); if(strlen(c2)<strlen(c1) puts(c1); printf("The length is:%dn",strlen(c1); if(strlen(c2)>strlen(c1) puts(c2); printf("The length is:%dn",strlen(c2);29. 从键盘输入 10 个战士的身高, 输出平均身高, 并找出哪些身高 低于平均身高。#in
44、clude "stdio.h" #define N 11 main() float aN,sum=0; int i;printf("Please input heigths:n");for(i=0;i<N-1;i+) scanf("%f",&ai); sum+=ai; aN-1=sum/(N-1);printf("The average is:%-6.2fn",aN-1);printf("n");printf("The answer are:n"); for(i
45、=0;i<N-1;i+)if(ai<aN-1)printf("%-8.2f",ai);30. 从键盘输入 10 个战士的身高, 输出平均身高, 并找出哪些身高 高于平均身高。#include "stdio.h"#define N 11 main() float aN,sum=0;int i; printf("Please input heigths:n");for(i=0;i<N-1;i+) scanf("%f",&ai); sum+=ai; aN-1=sum/(N-1);printf(&
46、quot;The average is:%-6.2fn",aN-1);printf("n");printf("Theanswer are:n");for(i=0;i<N-1;i+)if(ai>aN-1)printf("%-8.2f",ai);31. 从键盘输入 10 个战士的身高, 输出最高、最低的身高#include "stdio.h"#define N 10 main() float aN,min=99999,max=-99999;int i;printf("Please inp
47、ut heigths:n");for(i=0;i<N;i+) scanf("%f",&ai);printf("n"); for(i=0;i<N;i+) if(ai>max)max=ai;if(ai<min) min=ai;printf("max=%-6.2f,min=%-6.2f", max,min);。32. “百钱百鸡” 问题。百钱买百鸡, 鸡翁一值钱三,鸡母一值钱二, 鸡雏三值钱一,问鸡翁、鸡母、 鸡雏各几何?#include "stdio.h"main() int
48、jw,jm,jc;/* 公鸡最多 100/3=33 只,母鸡 最多 100/2=50 只, 小鸡最多 300只*/for(jw=1;jw<=33;jw+) for(jm=1;jm<=50;jm+)for(jc=1;jc<=300;jc+) if(jw*3+jm*2+jc/3=100&&jw+jm+jc=100) printf("JW=%d,JM=%d,JC=%dn",jw,jm,jc);33. 有三个小孩, 一个比一个大 2岁, 已知其年龄之和为 39,问这三个 小孩各几岁?#include "stdio.h"main() int a,b,c;for(a=1;a<=20;a+) for(b=1;b<=20;b+) for(c=1;c<=20;c+)if(a+2=b&am
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年濮阳市农村信用社联合社秋季校园招聘笔试备考题库(浓缩500题)及答案详解(全优)
- 2026国网广西高校毕业生提前批招聘(约450人)笔试模拟试题浓缩500题附答案详解(b卷)
- 2026国网上海市电力公司高校毕业生提前批招聘笔试模拟试题浓缩500题及答案详解(易错题)
- 独家分销合同
- 2026秋季国家管网集团华中公司高校毕业生招聘笔试备考题库(浓缩500题)及参考答案详解(模拟题)
- 2026届国家管网集团高校毕业生招聘考试备考题库(浓缩500题)及完整答案详解1套
- 2026国网贵州省高校毕业生提前批招聘(约450人)笔试模拟试题浓缩500题含答案详解(典型题)
- 2025国网内蒙古高校毕业生提前批招聘(约450人)笔试模拟试题浓缩500题附答案详解(考试直接用)
- 2026秋季国家管网集团西北公司高校毕业生招聘考试备考试题(浓缩500题)含答案详解(b卷)
- 2026国网甘肃省电力公司高校毕业生提前批招聘笔试参考题库浓缩500题附答案详解(满分必刷)
- 工程监理大纲监理方案服务方案
- C型钢检验报告
- 主体结构验收方案(示范文本)
- 八年级美术PPT课件 荷兰后印象派画家梵高作品介绍 《向日葵》《吃土豆的人》《割耳朵后的自画像》
- GB/T 3390.1-2013手动套筒扳手套筒
- GB 6675.1-2014玩具安全第1部分:基本规范
- 多功能注氧仪说明书课件
- 土方回填施工记录表
- 青岛版小学数学二年级上册《5的乘法口诀》课件
- 高中美术《初心与使命 时代的美术担当》 课件
- 西门子燃气轮机介绍课件
评论
0/150
提交评论