C语言课后作业50附参考答案.docx
《C语言课后作业50附参考答案.docx》由会员分享,可在线阅读,更多相关《C语言课后作业50附参考答案.docx(46页珍藏版)》请在冰豆网上搜索。
C语言课后作业50附参考答案
1.输入一个不超过五位的正整数,输出其逆数。
例如输入12345,输出应为54321。
#include
main(){
ints[5];
intn,j;
printf("请输入一个正的五位数");
scanf("%d",&n);
s[0]=n%10;
printf("%d",s[0]);
s[1]=(n%100-s[0])/10;
printf("%d",s[1]);
s[2]=(n%1000-s[0]-s[1])/100;
printf("%d",s[2]);
s[3]=(n%10000-s[0]-s[1]-s[2])/1000;
printf("%d",s[3]);
s[4]=(n%100000-s[0]-s[1]-s[2]-s[3])/10000;
printf("%d",s[4]);
printf("输出逆转后的5位数");
for(j=0;j<=4;j++){
printf("%d",s[j]);
}
2.计算1+2+3…+n的值,n是从键盘输入的自然数。
intn;
inti;
printf("请输入一个自然数:
");
i=n*(n+1)/2;
printf("输出1-n的自然数之和:
%d\n",i);
3.从终端(键盘)读入20个数据到数组中,统计其中正数的个数,并计算这些正数之和。
#definenaxx10
main()
{
ints[naxx];
inta[naxx];
inti=0;
intj=0;
intl=0;
intsum=0;
intk;
printf("请输入:
for(i=0;iscanf("%d",&s[i]);}for(j=0;j{if(s[j]>0){a[l]=s[j];sum+=a[l];l++;}}for(i=0;i{printf("%d\n",a[i]);}printf("输入数之和%d\n",sum);}4.从终端(键盘)将5个整数输入到数组a中,然后将a逆序复制到数组b中,并输出b中各元素的值。#include#definenaxx5main(){inti=0;intj=0;intk=0;ints[naxx];inta[naxx];for(i=0;i{s[i]=i;printf("%d\n",s[i]);}for(i=5;i>0;i--){a[j]=s[i-1];j++;printf("%d",a[j-1]);}}5.要将5张100元的大钞票,换成等值的50元,20元,10元,5元一张的小钞票,每种面值至少1张,编程求的需要多少张纸币。#include#definemoney500main(){inti,k;intj,l;printf("输出结果:\n");for(i=50+(money%50);i{for(j=20;(money%50==0)?jj<=i-15;j+=20){for(k=10;k{printf("%d张50%d张20%d张10%d张5\n",(money-i)/50,j/20,k/10,(i-j-k)/5);}}}}6.求n以内(不包括n)同时能被3和7整除的所有自然数之和的平方根s,n从键盘输入。例如若n为1000时,函数值应为:s=153.909064。#include#includemain(){inti;intn=1;intsum=0;printf("输入一个>21的数:");scanf("%d",&n);if(n>21){n--;for(;n>=21;n--){if(n%3==0&&n%7==0){printf("%d",n);sum+=n;i=sqrt(sum);}}printf("\n");}else{printf("输入错误:\n");}}7.一辆卡车违反交通规则,撞人后逃跑。现场有三人目击事件,但都没有记住车号,只记下车号的一些特征。甲说:牌照的前两位数字是相同的;乙说:牌照的后两位数字是相同的,但与前两位不同;丙是数学家,他说:四位的车号刚好是一个整数的平方。请根据以上线索找出车号。#includemain(){inti;intj;inta,b,c,d;for(i=31;i<100;i++){j=i*i;a=j%10;b=(j%100-a)/10;c=(j%1000-a-b)/100;d=j/1000;if((a==b&&c==d)&&a!=c){printf("输出牌号:%d\n",j);}}}8.输入1~10之间的一个数字,输出它对应的英文单词。#include//第八题:#include#includemain(){intq;intt;charm[10]={'a','b','c','d','e','f','g','h','i','j'};//printf("%c",m[2]);printf("请输入1-10\n");scanf("%d",&q);t=q-1;printf("%d对应的字母是:%c\n",q,m[t]);}9.个位数为6且能被3整除但不能被5整除的三位自然数共有多少个,分别是哪些?#include//第九题#include#includemain(){inti;for(i=100;i<1000;i++){if(i%10==6){if(i%3==0){if(i%5!=0){printf("%d\n",i);}}//printf("%d\n",i);//continue;}}}10.输入某年某月某日,判断这一天是这一年的第几天?#include//第十题#include#includemain(){inty,m,d;scanf("%d%d%d",&y,&m,&d);if(y%4==0&y%100!=0|y%400==0){switch(m){case1:printf("是今年的%d天\n",d);break;case2:printf("是今年的%d天\n",d+31);break;case3:printf("是今年的%d天\n",d+31+29);break;case4:printf("是今年的%d天\n",d+31+29+31);break;case5:printf("是今年的%d天\n",d+31+29+31+30);break;case6:printf("是今年的%d天\n",d+31+29+31+30+31);break;case7:printf("是今年的%d天\n",d+31+29+31+30+31+30);break;case8:printf("是今年的%d天\n",d+31+29+31+30+31+31+31);break;case9:printf("是今年的%d天\n",d+31+29+31+30+31+31+31+31);break;case10:printf("是今年的%d天\n",d+31+29+31+30+31+31+31+31+30);break;case11:printf("是今年的%d天\n",d+31+29+31+30+31+31+31+31+30+31);break;case12:printf("是今年的%d天\n",d+31+29+31+30+31+31+31+31+30+31+30);break;}}else{switch(m){case1:printf("是今年的%d天\n",d);break;case2:printf("是今年的%d天\n",d+31);break;case3:printf("是今年的%d天\n",d+31+28);break;case4:printf("是今年的%d天\n",d+31+28+31);break;case5:printf("是今年的%d天\n",d+31+28+31+30);break;case6:printf("是今年的%d天\n",d+31+28+31+30+31);break;case7:printf("是今年的%d天\n",d+31+28+31+30+31+30);break;case8:printf("是今年的%d天\n",d+31+28+31+30+31+31+31);break;case9:printf("是今年的%d天\n",d+31+28+31+30+31+31+31+31);break;case10:printf("是今年的%d天\n",d+31+28+31+30+31+31+31+31+30);break;case11:printf("是今年的%d天\n",d+31+28+31+30+31+31+31+31+30+31);break;case12:printf("是今年的%d天\n",d+31+28+31+30+31+31+31+31+30+31+30);break;}}}11.两个乒乓球队进行比赛,各出三人。甲队为a,b,c三人,乙队为x,y,z三人。已抽签决定比赛名单。有人向队员打听比赛的名单。a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单。#includeintmain(){chari;charj;chark;for(i='x';i<='z';i++){for(j='x';j<='z';j++){if(i!=j){for(k='x';k<='y';k++){if(i!=k&&j!=k){if(i!='x'&&k!='x'&&k!='z'){printf("a--->%c\nb--->%c\nc--->%c",i,j,k);}}}}}}return0;}12.有5个人坐在一起,问第五个人多少岁?他说比第4个人大2岁。问第4个人岁数,他说比第3个人大2岁。问第三个人,又说比第2人大两岁。问第2个人,说比第一个人大两岁。最后问第一个人,他说是10岁。请问第五个人多大?#includeintfac(intn);intmain(){inta=5;printf("di5gerendedesuishushi%d\n",fac(a));return0;}intfac(intn){if(n==1){return10;}else{return2+fac(n-1);}}13.输入某三角形的三个边的长度,判断出这是个什么三角形(等腰、等边、任意,或不能构成)。#includeintmain(){inta,b,c;printf("pleaseenterabc\n");scanf("%d%d%d",&a,&b,&c);//printf("%d\n%d\n%d\n",a,b,c);if((a+b<=c)||(a-b>=c)){printf("bunenggouchengsanjiaoxing\n");}elseif(a==b&&b==c){printf("dengbiansanjiaoxing\n");}return0;}14.输入10个数,分别统计其中正数、负数、零的个数。#include"stdio.h"main(){inta[10],i;s1=0;s2=0;s3=0;printf("请输入10个数:\n");for(i=0;i<10;i++)scanf("%d",&a[i]);for(i=0;i<10;i++){if(a[i]<0)s1++;if(a[i]==0)s2++;if(a[i]>0)s3++;}printf("负数为%d个,零为%d个,正数为%d个",s1,s2,s3);}15.先随机产生N个三位自然数输出,然后再输出其中同时是3、5、7倍数的数。(设N为100)#include"stdio.h"#include"time.h"main(){inta,c,n;srand((unsigned)time(NULL));for(a=0;a<100;a++){c=rand()%1000;if(c>=100&&c%3==0&&c%5==0&&c%7==0){printf("%d\n",c);}}}16.用for编程找出100~200中的完全平方数。#includeintmain(){inti=10;intb;for(i=10;i<=15;i++){b=i*i;if(b<=200&&b>=100){printf("%d\n",b);}}return0;}17.从终端输入三个正实数,判断这三个数能否构成直角三角形。#include"stdio.h"main(){inta,b,c;printf("请输入三个正实数:\n");scanf("%d%d%d",&a,&b,&c);if(a*a+b*b==c*c)printf("这是直角三角形!\n");elseprintf("不构成直角三角形!\n");}18.输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。#includeintmain(){intc;intnword=0;intnspace=0;intnother=0;intnnum=0;while((c=getchar())!=EOF){if((c>='a'&&c<='z')||(c<='Z'&&c>='A')){nword++;}elseif(c>='0'&&c<='9'){nnum++;}elseif(c==''){nspace++;}else{nother++;}}printf("space:%d\n",nspace);printf("num:%d\n",nnum);printf("other:%d\n",nother);printf("word:%d\n",nword);return0;}19.输入一个字串,判断它是否是对称串。如”abcdcba”是对称串,不是。#includeintpanduan(char*s);intmain(){chars[500];printf("pleaseenterastring:\n");scanf("%s",s);panduan(s);return0;}intpanduan(char*s){char*p=s;char*q=s;while(*q!='\0'){q++;}q--;while((q-p)>1){if(*p!=*q){printf("buduichen!\n");return1;}q--;p++;}printf("duichen");return0;}20.随机产生N个大写字母输出,然后统计其中共有多少个元音字符。(设N为50)#include#include#include#defineN10intisyuan(chars);intmain(){chars[N];inti;intcount=0;charzimubiao[]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};srand(time(NULL));for(i=0;i{s[i]=zimubiao[rand()%26];}for(i=0;i{printf("%c",s[i]);}printf("\n");for(i=0;i{if(isyuan(s[i])){count++;}}printf("gongyouyuanyin%dge\n",count);return0;}intisyuan(chars){intj;charyuanyinbiao[]={'A','E','I','O','U'};for(j=0;j<5;j++){if(s==yuanyinbiao[j]){return1;}}return0;}21.找出三位自然数中的所有素数,要求判断x素数用自定义函数data(x)实现。#includeintdata(intx);intmain(){inti;for(i=100;i<=999;i++){if(data(i)){printf("%dshisushu\n",i);}}return0;}//sushufanhui1,bushifanhui0.intdata(intx){intj;for(j=2;j{if((x%j)==0){return0;}}return1;}22.输出n行由“#”组成的矩形,每行“#”的个数为m个,其中n、m由终端(键盘)输入。要求输出m个“#”功能由函数satr(m)函数实现。#includevoidsatr(intm);intm,n;intmain(){printf("qingshurumndezhi:\n");scanf("%d",&m);scanf("%d",&n);satr(m);return0;}voidsatr(m){inti,j;for(i=0;i{for(j=0;j{printf("#");}printf("\n");}}23.若ax2+bx+c=0有实根,则求之。#include#includeintmain(){floata,b,c,disc,x1,x2,p,q;scanf("a=%f,b=%f,c=%f",&a,&b,&c);disc=b*b-4*a*c;if(disc<0){printf("meiyoushigen");}else{p=-b/(2*a);q=sqrt(disc)/(2*a);x1=p+q;x2=p-q;printf("\nx1=%5.2f\nx2=%5.2f\n",x1,x2);}return0;}24.从键盘输入两个字串,判断它们是否相同。#
scanf("%d",&s[i]);
for(j=0;j{if(s[j]>0){a[l]=s[j];sum+=a[l];l++;}}for(i=0;i{printf("%d\n",a[i]);}printf("输入数之和%d\n",sum);}4.从终端(键盘)将5个整数输入到数组a中,然后将a逆序复制到数组b中,并输出b中各元素的值。#include#definenaxx5main(){inti=0;intj=0;intk=0;ints[naxx];inta[naxx];for(i=0;i{s[i]=i;printf("%d\n",s[i]);}for(i=5;i>0;i--){a[j]=s[i-1];j++;printf("%d",a[j-1]);}}5.要将5张100元的大钞票,换成等值的50元,20元,10元,5元一张的小钞票,每种面值至少1张,编程求的需要多少张纸币。#include#definemoney500main(){inti,k;intj,l;printf("输出结果:\n");for(i=50+(money%50);i{for(j=20;(money%50==0)?jj<=i-15;j+=20){for(k=10;k{printf("%d张50%d张20%d张10%d张5\n",(money-i)/50,j/20,k/10,(i-j-k)/5);}}}}6.求n以内(不包括n)同时能被3和7整除的所有自然数之和的平方根s,n从键盘输入。例如若n为1000时,函数值应为:s=153.909064。#include#includemain(){inti;intn=1;intsum=0;printf("输入一个>21的数:");scanf("%d",&n);if(n>21){n--;for(;n>=21;n--){if(n%3==0&&n%7==0){printf("%d",n);sum+=n;i=sqrt(sum);}}printf("\n");}else{printf("输入错误:\n");}}7.一辆卡车违反交通规则,撞人后逃跑。现场有三人目击事件,但都没有记住车号,只记下车号的一些特征。甲说:牌照的前两位数字是相同的;乙说:牌照的后两位数字是相同的,但与前两位不同;丙是数学家,他说:四位的车号刚好是一个整数的平方。请根据以上线索找出车号。#includemain(){inti;intj;inta,b,c,d;for(i=31;i<100;i++){j=i*i;a=j%10;b=(j%100-a)/10;c=(j%1000-a-b)/100;d=j/1000;if((a==b&&c==d)&&a!=c){printf("输出牌号:%d\n",j);}}}8.输入1~10之间的一个数字,输出它对应的英文单词。#include//第八题:#include#includemain(){intq;intt;charm[10]={'a','b','c','d','e','f','g','h','i','j'};//printf("%c",m[2]);printf("请输入1-10\n");scanf("%d",&q);t=q-1;printf("%d对应的字母是:%c\n",q,m[t]);}9.个位数为6且能被3整除但不能被5整除的三位自然数共有多少个,分别是哪些?#include//第九题#include#includemain(){inti;for(i=100;i<1000;i++){if(i%10==6){if(i%3==0){if(i%5!=0){printf("%d\n",i);}}//printf("%d\n",i);//continue;}}}10.输入某年某月某日,判断这一天是这一年的第几天?#include//第十题#include#includemain(){inty,m,d;scanf("%d%d%d",&y,&m,&d);if(y%4==0&y%100!=0|y%400==0){switch(m){case1:printf("是今年的%d天\n",d);break;case2:printf("是今年的%d天\n",d+31);break;case3:printf("是今年的%d天\n",d+31+29);break;case4:printf("是今年的%d天\n",d+31+29+31);break;case5:printf("是今年的%d天\n",d+31+29+31+30);break;case6:printf("是今年的%d天\n",d+31+29+31+30+31);break;case7:printf("是今年的%d天\n",d+31+29+31+30+31+30);break;case8:printf("是今年的%d天\n",d+31+29+31+30+31+31+31);break;case9:printf("是今年的%d天\n",d+31+29+31+30+31+31+31+31);break;case10:printf("是今年的%d天\n",d+31+29+31+30+31+31+31+31+30);break;case11:printf("是今年的%d天\n",d+31+29+31+30+31+31+31+31+30+31);break;case12:printf("是今年的%d天\n",d+31+29+31+30+31+31+31+31+30+31+30);break;}}else{switch(m){case1:printf("是今年的%d天\n",d);break;case2:printf("是今年的%d天\n",d+31);break;case3:printf("是今年的%d天\n",d+31+28);break;case4:printf("是今年的%d天\n",d+31+28+31);break;case5:printf("是今年的%d天\n",d+31+28+31+30);break;case6:printf("是今年的%d天\n",d+31+28+31+30+31);break;case7:printf("是今年的%d天\n",d+31+28+31+30+31+30);break;case8:printf("是今年的%d天\n",d+31+28+31+30+31+31+31);break;case9:printf("是今年的%d天\n",d+31+28+31+30+31+31+31+31);break;case10:printf("是今年的%d天\n",d+31+28+31+30+31+31+31+31+30);break;case11:printf("是今年的%d天\n",d+31+28+31+30+31+31+31+31+30+31);break;case12:printf("是今年的%d天\n",d+31+28+31+30+31+31+31+31+30+31+30);break;}}}11.两个乒乓球队进行比赛,各出三人。甲队为a,b,c三人,乙队为x,y,z三人。已抽签决定比赛名单。有人向队员打听比赛的名单。a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单。#includeintmain(){chari;charj;chark;for(i='x';i<='z';i++){for(j='x';j<='z';j++){if(i!=j){for(k='x';k<='y';k++){if(i!=k&&j!=k){if(i!='x'&&k!='x'&&k!='z'){printf("a--->%c\nb--->%c\nc--->%c",i,j,k);}}}}}}return0;}12.有5个人坐在一起,问第五个人多少岁?他说比第4个人大2岁。问第4个人岁数,他说比第3个人大2岁。问第三个人,又说比第2人大两岁。问第2个人,说比第一个人大两岁。最后问第一个人,他说是10岁。请问第五个人多大?#includeintfac(intn);intmain(){inta=5;printf("di5gerendedesuishushi%d\n",fac(a));return0;}intfac(intn){if(n==1){return10;}else{return2+fac(n-1);}}13.输入某三角形的三个边的长度,判断出这是个什么三角形(等腰、等边、任意,或不能构成)。#includeintmain(){inta,b,c;printf("pleaseenterabc\n");scanf("%d%d%d",&a,&b,&c);//printf("%d\n%d\n%d\n",a,b,c);if((a+b<=c)||(a-b>=c)){printf("bunenggouchengsanjiaoxing\n");}elseif(a==b&&b==c){printf("dengbiansanjiaoxing\n");}return0;}14.输入10个数,分别统计其中正数、负数、零的个数。#include"stdio.h"main(){inta[10],i;s1=0;s2=0;s3=0;printf("请输入10个数:\n");for(i=0;i<10;i++)scanf("%d",&a[i]);for(i=0;i<10;i++){if(a[i]<0)s1++;if(a[i]==0)s2++;if(a[i]>0)s3++;}printf("负数为%d个,零为%d个,正数为%d个",s1,s2,s3);}15.先随机产生N个三位自然数输出,然后再输出其中同时是3、5、7倍数的数。(设N为100)#include"stdio.h"#include"time.h"main(){inta,c,n;srand((unsigned)time(NULL));for(a=0;a<100;a++){c=rand()%1000;if(c>=100&&c%3==0&&c%5==0&&c%7==0){printf("%d\n",c);}}}16.用for编程找出100~200中的完全平方数。#includeintmain(){inti=10;intb;for(i=10;i<=15;i++){b=i*i;if(b<=200&&b>=100){printf("%d\n",b);}}return0;}17.从终端输入三个正实数,判断这三个数能否构成直角三角形。#include"stdio.h"main(){inta,b,c;printf("请输入三个正实数:\n");scanf("%d%d%d",&a,&b,&c);if(a*a+b*b==c*c)printf("这是直角三角形!\n");elseprintf("不构成直角三角形!\n");}18.输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。#includeintmain(){intc;intnword=0;intnspace=0;intnother=0;intnnum=0;while((c=getchar())!=EOF){if((c>='a'&&c<='z')||(c<='Z'&&c>='A')){nword++;}elseif(c>='0'&&c<='9'){nnum++;}elseif(c==''){nspace++;}else{nother++;}}printf("space:%d\n",nspace);printf("num:%d\n",nnum);printf("other:%d\n",nother);printf("word:%d\n",nword);return0;}19.输入一个字串,判断它是否是对称串。如”abcdcba”是对称串,不是。#includeintpanduan(char*s);intmain(){chars[500];printf("pleaseenterastring:\n");scanf("%s",s);panduan(s);return0;}intpanduan(char*s){char*p=s;char*q=s;while(*q!='\0'){q++;}q--;while((q-p)>1){if(*p!=*q){printf("buduichen!\n");return1;}q--;p++;}printf("duichen");return0;}20.随机产生N个大写字母输出,然后统计其中共有多少个元音字符。(设N为50)#include#include#include#defineN10intisyuan(chars);intmain(){chars[N];inti;intcount=0;charzimubiao[]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};srand(time(NULL));for(i=0;i{s[i]=zimubiao[rand()%26];}for(i=0;i{printf("%c",s[i]);}printf("\n");for(i=0;i{if(isyuan(s[i])){count++;}}printf("gongyouyuanyin%dge\n",count);return0;}intisyuan(chars){intj;charyuanyinbiao[]={'A','E','I','O','U'};for(j=0;j<5;j++){if(s==yuanyinbiao[j]){return1;}}return0;}21.找出三位自然数中的所有素数,要求判断x素数用自定义函数data(x)实现。#includeintdata(intx);intmain(){inti;for(i=100;i<=999;i++){if(data(i)){printf("%dshisushu\n",i);}}return0;}//sushufanhui1,bushifanhui0.intdata(intx){intj;for(j=2;j{if((x%j)==0){return0;}}return1;}22.输出n行由“#”组成的矩形,每行“#”的个数为m个,其中n、m由终端(键盘)输入。要求输出m个“#”功能由函数satr(m)函数实现。#includevoidsatr(intm);intm,n;intmain(){printf("qingshurumndezhi:\n");scanf("%d",&m);scanf("%d",&n);satr(m);return0;}voidsatr(m){inti,j;for(i=0;i{for(j=0;j{printf("#");}printf("\n");}}23.若ax2+bx+c=0有实根,则求之。#include#includeintmain(){floata,b,c,disc,x1,x2,p,q;scanf("a=%f,b=%f,c=%f",&a,&b,&c);disc=b*b-4*a*c;if(disc<0){printf("meiyoushigen");}else{p=-b/(2*a);q=sqrt(disc)/(2*a);x1=p+q;x2=p-q;printf("\nx1=%5.2f\nx2=%5.2f\n",x1,x2);}return0;}24.从键盘输入两个字串,判断它们是否相同。#
{if(s[j]>0)
{a[l]=s[j];
sum+=a[l];
l++;
for(i=0;i{printf("%d\n",a[i]);}printf("输入数之和%d\n",sum);}4.从终端(键盘)将5个整数输入到数组a中,然后将a逆序复制到数组b中,并输出b中各元素的值。#include#definenaxx5main(){inti=0;intj=0;intk=0;ints[naxx];inta[naxx];for(i=0;i{s[i]=i;printf("%d\n",s[i]);}for(i=5;i>0;i--){a[j]=s[i-1];j++;printf("%d",a[j-1]);}}5.要将5张100元的大钞票,换成等值的50元,20元,10元,5元一张的小钞票,每种面值至少1张,编程求的需要多少张纸币。#include#definemoney500main(){inti,k;intj,l;printf("输出结果:\n");for(i=50+(money%50);i{for(j=20;(money%50==0)?jj<=i-15;j+=20){for(k=10;k{printf("%d张50%d张20%d张10%d张5\n",(money-i)/50,j/20,k/10,(i-j-k)/5);}}}}6.求n以内(不包括n)同时能被3和7整除的所有自然数之和的平方根s,n从键盘输入。例如若n为1000时,函数值应为:s=153.909064。#include#includemain(){inti;intn=1;intsum=0;printf("输入一个>21的数:");scanf("%d",&n);if(n>21){n--;for(;n>=21;n--){if(n%3==0&&n%7==0){printf("%d",n);sum+=n;i=sqrt(sum);}}printf("\n");}else{printf("输入错误:\n");}}7.一辆卡车违反交通规则,撞人后逃跑。现场有三人目击事件,但都没有记住车号,只记下车号的一些特征。甲说:牌照的前两位数字是相同的;乙说:牌照的后两位数字是相同的,但与前两位不同;丙是数学家,他说:四位的车号刚好是一个整数的平方。请根据以上线索找出车号。#includemain(){inti;intj;inta,b,c,d;for(i=31;i<100;i++){j=i*i;a=j%10;b=(j%100-a)/10;c=(j%1000-a-b)/100;d=j/1000;if((a==b&&c==d)&&a!=c){printf("输出牌号:%d\n",j);}}}8.输入1~10之间的一个数字,输出它对应的英文单词。#include//第八题:#include#includemain(){intq;intt;charm[10]={'a','b','c','d','e','f','g','h','i','j'};//printf("%c",m[2]);printf("请输入1-10\n");scanf("%d",&q);t=q-1;printf("%d对应的字母是:%c\n",q,m[t]);}9.个位数为6且能被3整除但不能被5整除的三位自然数共有多少个,分别是哪些?#include//第九题#include#includemain(){inti;for(i=100;i<1000;i++){if(i%10==6){if(i%3==0){if(i%5!=0){printf("%d\n",i);}}//printf("%d\n",i);//continue;}}}10.输入某年某月某日,判断这一天是这一年的第几天?#include//第十题#include#includemain(){inty,m,d;scanf("%d%d%d",&y,&m,&d);if(y%4==0&y%100!=0|y%400==0){switch(m){case1:printf("是今年的%d天\n",d);break;case2:printf("是今年的%d天\n",d+31);break;case3:printf("是今年的%d天\n",d+31+29);break;case4:printf("是今年的%d天\n",d+31+29+31);break;case5:printf("是今年的%d天\n",d+31+29+31+30);break;case6:printf("是今年的%d天\n",d+31+29+31+30+31);break;case7:printf("是今年的%d天\n",d+31+29+31+30+31+30);break;case8:printf("是今年的%d天\n",d+31+29+31+30+31+31+31);break;case9:printf("是今年的%d天\n",d+31+29+31+30+31+31+31+31);break;case10:printf("是今年的%d天\n",d+31+29+31+30+31+31+31+31+30);break;case11:printf("是今年的%d天\n",d+31+29+31+30+31+31+31+31+30+31);break;case12:printf("是今年的%d天\n",d+31+29+31+30+31+31+31+31+30+31+30);break;}}else{switch(m){case1:printf("是今年的%d天\n",d);break;case2:printf("是今年的%d天\n",d+31);break;case3:printf("是今年的%d天\n",d+31+28);break;case4:printf("是今年的%d天\n",d+31+28+31);break;case5:printf("是今年的%d天\n",d+31+28+31+30);break;case6:printf("是今年的%d天\n",d+31+28+31+30+31);break;case7:printf("是今年的%d天\n",d+31+28+31+30+31+30);break;case8:printf("是今年的%d天\n",d+31+28+31+30+31+31+31);break;case9:printf("是今年的%d天\n",d+31+28+31+30+31+31+31+31);break;case10:printf("是今年的%d天\n",d+31+28+31+30+31+31+31+31+30);break;case11:printf("是今年的%d天\n",d+31+28+31+30+31+31+31+31+30+31);break;case12:printf("是今年的%d天\n",d+31+28+31+30+31+31+31+31+30+31+30);break;}}}11.两个乒乓球队进行比赛,各出三人。甲队为a,b,c三人,乙队为x,y,z三人。已抽签决定比赛名单。有人向队员打听比赛的名单。a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单。#includeintmain(){chari;charj;chark;for(i='x';i<='z';i++){for(j='x';j<='z';j++){if(i!=j){for(k='x';k<='y';k++){if(i!=k&&j!=k){if(i!='x'&&k!='x'&&k!='z'){printf("a--->%c\nb--->%c\nc--->%c",i,j,k);}}}}}}return0;}12.有5个人坐在一起,问第五个人多少岁?他说比第4个人大2岁。问第4个人岁数,他说比第3个人大2岁。问第三个人,又说比第2人大两岁。问第2个人,说比第一个人大两岁。最后问第一个人,他说是10岁。请问第五个人多大?#includeintfac(intn);intmain(){inta=5;printf("di5gerendedesuishushi%d\n",fac(a));return0;}intfac(intn){if(n==1){return10;}else{return2+fac(n-1);}}13.输入某三角形的三个边的长度,判断出这是个什么三角形(等腰、等边、任意,或不能构成)。#includeintmain(){inta,b,c;printf("pleaseenterabc\n");scanf("%d%d%d",&a,&b,&c);//printf("%d\n%d\n%d\n",a,b,c);if((a+b<=c)||(a-b>=c)){printf("bunenggouchengsanjiaoxing\n");}elseif(a==b&&b==c){printf("dengbiansanjiaoxing\n");}return0;}14.输入10个数,分别统计其中正数、负数、零的个数。#include"stdio.h"main(){inta[10],i;s1=0;s2=0;s3=0;printf("请输入10个数:\n");for(i=0;i<10;i++)scanf("%d",&a[i]);for(i=0;i<10;i++){if(a[i]<0)s1++;if(a[i]==0)s2++;if(a[i]>0)s3++;}printf("负数为%d个,零为%d个,正数为%d个",s1,s2,s3);}15.先随机产生N个三位自然数输出,然后再输出其中同时是3、5、7倍数的数。(设N为100)#include"stdio.h"#include"time.h"main(){inta,c,n;srand((unsigned)time(NULL));for(a=0;a<100;a++){c=rand()%1000;if(c>=100&&c%3==0&&c%5==0&&c%7==0){printf("%d\n",c);}}}16.用for编程找出100~200中的完全平方数。#includeintmain(){inti=10;intb;for(i=10;i<=15;i++){b=i*i;if(b<=200&&b>=100){printf("%d\n",b);}}return0;}17.从终端输入三个正实数,判断这三个数能否构成直角三角形。#include"stdio.h"main(){inta,b,c;printf("请输入三个正实数:\n");scanf("%d%d%d",&a,&b,&c);if(a*a+b*b==c*c)printf("这是直角三角形!\n");elseprintf("不构成直角三角形!\n");}18.输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。#includeintmain(){intc;intnword=0;intnspace=0;intnother=0;intnnum=0;while((c=getchar())!=EOF){if((c>='a'&&c<='z')||(c<='Z'&&c>='A')){nword++;}elseif(c>='0'&&c<='9'){nnum++;}elseif(c==''){nspace++;}else{nother++;}}printf("space:%d\n",nspace);printf("num:%d\n",nnum);printf("other:%d\n",nother);printf("word:%d\n",nword);return0;}19.输入一个字串,判断它是否是对称串。如”abcdcba”是对称串,不是。#includeintpanduan(char*s);intmain(){chars[500];printf("pleaseenterastring:\n");scanf("%s",s);panduan(s);return0;}intpanduan(char*s){char*p=s;char*q=s;while(*q!='\0'){q++;}q--;while((q-p)>1){if(*p!=*q){printf("buduichen!\n");return1;}q--;p++;}printf("duichen");return0;}20.随机产生N个大写字母输出,然后统计其中共有多少个元音字符。(设N为50)#include#include#include#defineN10intisyuan(chars);intmain(){chars[N];inti;intcount=0;charzimubiao[]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};srand(time(NULL));for(i=0;i{s[i]=zimubiao[rand()%26];}for(i=0;i{printf("%c",s[i]);}printf("\n");for(i=0;i{if(isyuan(s[i])){count++;}}printf("gongyouyuanyin%dge\n",count);return0;}intisyuan(chars){intj;charyuanyinbiao[]={'A','E','I','O','U'};for(j=0;j<5;j++){if(s==yuanyinbiao[j]){return1;}}return0;}21.找出三位自然数中的所有素数,要求判断x素数用自定义函数data(x)实现。#includeintdata(intx);intmain(){inti;for(i=100;i<=999;i++){if(data(i)){printf("%dshisushu\n",i);}}return0;}//sushufanhui1,bushifanhui0.intdata(intx){intj;for(j=2;j{if((x%j)==0){return0;}}return1;}22.输出n行由“#”组成的矩形,每行“#”的个数为m个,其中n、m由终端(键盘)输入。要求输出m个“#”功能由函数satr(m)函数实现。#includevoidsatr(intm);intm,n;intmain(){printf("qingshurumndezhi:\n");scanf("%d",&m);scanf("%d",&n);satr(m);return0;}voidsatr(m){inti,j;for(i=0;i{for(j=0;j{printf("#");}printf("\n");}}23.若ax2+bx+c=0有实根,则求之。#include#includeintmain(){floata,b,c,disc,x1,x2,p,q;scanf("a=%f,b=%f,c=%f",&a,&b,&c);disc=b*b-4*a*c;if(disc<0){printf("meiyoushigen");}else{p=-b/(2*a);q=sqrt(disc)/(2*a);x1=p+q;x2=p-q;printf("\nx1=%5.2f\nx2=%5.2f\n",x1,x2);}return0;}24.从键盘输入两个字串,判断它们是否相同。#
{printf("%d\n",a[i]);}
printf("输入数之和%d\n",sum);
4.从终端(键盘)将5个整数输入到数组a中,然后将a逆序复制到数组b中,并输出b中各元素的值。
#definenaxx5
intk=0;
for(i=0;i{s[i]=i;printf("%d\n",s[i]);}for(i=5;i>0;i--){a[j]=s[i-1];j++;printf("%d",a[j-1]);}}5.要将5张100元的大钞票,换成等值的50元,20元,10元,5元一张的小钞票,每种面值至少1张,编程求的需要多少张纸币。#include#definemoney500main(){inti,k;intj,l;printf("输出结果:\n");for(i=50+(money%50);i{for(j=20;(money%50==0)?jj<=i-15;j+=20){for(k=10;k{printf("%d张50%d张20%d张10%d张5\n",(money-i)/50,j/20,k/10,(i-j-k)/5);}}}}6.求n以内(不包括n)同时能被3和7整除的所有自然数之和的平方根s,n从键盘输入。例如若n为1000时,函数值应为:s=153.909064。#include#includemain(){inti;intn=1;intsum=0;printf("输入一个>21的数:");scanf("%d",&n);if(n>21){n--;for(;n>=21;n--){if(n%3==0&&n%7==0){printf("%d",n);sum+=n;i=sqrt(sum);}}printf("\n");}else{printf("输入错误:\n");}}7.一辆卡车违反交通规则,撞人后逃跑。现场有三人目击事件,但都没有记住车号,只记下车号的一些特征。甲说:牌照的前两位数字是相同的;乙说:牌照的后两位数字是相同的,但与前两位不同;丙是数学家,他说:四位的车号刚好是一个整数的平方。请根据以上线索找出车号。#includemain(){inti;intj;inta,b,c,d;for(i=31;i<100;i++){j=i*i;a=j%10;b=(j%100-a)/10;c=(j%1000-a-b)/100;d=j/1000;if((a==b&&c==d)&&a!=c){printf("输出牌号:%d\n",j);}}}8.输入1~10之间的一个数字,输出它对应的英文单词。#include//第八题:#include#includemain(){intq;intt;charm[10]={'a','b','c','d','e','f','g','h','i','j'};//printf("%c",m[2]);printf("请输入1-10\n");scanf("%d",&q);t=q-1;printf("%d对应的字母是:%c\n",q,m[t]);}9.个位数为6且能被3整除但不能被5整除的三位自然数共有多少个,分别是哪些?#include//第九题#include#includemain(){inti;for(i=100;i<1000;i++){if(i%10==6){if(i%3==0){if(i%5!=0){printf("%d\n",i);}}//printf("%d\n",i);//continue;}}}10.输入某年某月某日,判断这一天是这一年的第几天?#include//第十题#include#includemain(){inty,m,d;scanf("%d%d%d",&y,&m,&d);if(y%4==0&y%100!=0|y%400==0){switch(m){case1:printf("是今年的%d天\n",d);break;case2:printf("是今年的%d天\n",d+31);break;case3:printf("是今年的%d天\n",d+31+29);break;case4:printf("是今年的%d天\n",d+31+29+31);break;case5:printf("是今年的%d天\n",d+31+29+31+30);break;case6:printf("是今年的%d天\n",d+31+29+31+30+31);break;case7:printf("是今年的%d天\n",d+31+29+31+30+31+30);break;case8:printf("是今年的%d天\n",d+31+29+31+30+31+31+31);break;case9:printf("是今年的%d天\n",d+31+29+31+30+31+31+31+31);break;case10:printf("是今年的%d天\n",d+31+29+31+30+31+31+31+31+30);break;case11:printf("是今年的%d天\n",d+31+29+31+30+31+31+31+31+30+31);break;case12:printf("是今年的%d天\n",d+31+29+31+30+31+31+31+31+30+31+30);break;}}else{switch(m){case1:printf("是今年的%d天\n",d);break;case2:printf("是今年的%d天\n",d+31);break;case3:printf("是今年的%d天\n",d+31+28);break;case4:printf("是今年的%d天\n",d+31+28+31);break;case5:printf("是今年的%d天\n",d+31+28+31+30);break;case6:printf("是今年的%d天\n",d+31+28+31+30+31);break;case7:printf("是今年的%d天\n",d+31+28+31+30+31+30);break;case8:printf("是今年的%d天\n",d+31+28+31+30+31+31+31);break;case9:printf("是今年的%d天\n",d+31+28+31+30+31+31+31+31);break;case10:printf("是今年的%d天\n",d+31+28+31+30+31+31+31+31+30);break;case11:printf("是今年的%d天\n",d+31+28+31+30+31+31+31+31+30+31);break;case12:printf("是今年的%d天\n",d+31+28+31+30+31+31+31+31+30+31+30);break;}}}11.两个乒乓球队进行比赛,各出三人。甲队为a,b,c三人,乙队为x,y,z三人。已抽签决定比赛名单。有人向队员打听比赛的名单。a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单。#includeintmain(){chari;charj;chark;for(i='x';i<='z';i++){for(j='x';j<='z';j++){if(i!=j){for(k='x';k<='y';k++){if(i!=k&&j!=k){if(i!='x'&&k!='x'&&k!='z'){printf("a--->%c\nb--->%c\nc--->%c",i,j,k);}}}}}}return0;}12.有5个人坐在一起,问第五个人多少岁?他说比第4个人大2岁。问第4个人岁数,他说比第3个人大2岁。问第三个人,又说比第2人大两岁。问第2个人,说比第一个人大两岁。最后问第一个人,他说是10岁。请问第五个人多大?#includeintfac(intn);intmain(){inta=5;printf("di5gerendedesuishushi%d\n",fac(a));return0;}intfac(intn){if(n==1){return10;}else{return2+fac(n-1);}}13.输入某三角形的三个边的长度,判断出这是个什么三角形(等腰、等边、任意,或不能构成)。#includeintmain(){inta,b,c;printf("pleaseenterabc\n");scanf("%d%d%d",&a,&b,&c);//printf("%d\n%d\n%d\n",a,b,c);if((a+b<=c)||(a-b>=c)){printf("bunenggouchengsanjiaoxing\n");}elseif(a==b&&b==c){printf("dengbiansanjiaoxing\n");}return0;}14.输入10个数,分别统计其中正数、负数、零的个数。#include"stdio.h"main(){inta[10],i;s1=0;s2=0;s3=0;printf("请输入10个数:\n");for(i=0;i<10;i++)scanf("%d",&a[i]);for(i=0;i<10;i++){if(a[i]<0)s1++;if(a[i]==0)s2++;if(a[i]>0)s3++;}printf("负数为%d个,零为%d个,正数为%d个",s1,s2,s3);}15.先随机产生N个三位自然数输出,然后再输出其中同时是3、5、7倍数的数。(设N为100)#include"stdio.h"#include"time.h"main(){inta,c,n;srand((unsigned)time(NULL));for(a=0;a<100;a++){c=rand()%1000;if(c>=100&&c%3==0&&c%5==0&&c%7==0){printf("%d\n",c);}}}16.用for编程找出100~200中的完全平方数。#includeintmain(){inti=10;intb;for(i=10;i<=15;i++){b=i*i;if(b<=200&&b>=100){printf("%d\n",b);}}return0;}17.从终端输入三个正实数,判断这三个数能否构成直角三角形。#include"stdio.h"main(){inta,b,c;printf("请输入三个正实数:\n");scanf("%d%d%d",&a,&b,&c);if(a*a+b*b==c*c)printf("这是直角三角形!\n");elseprintf("不构成直角三角形!\n");}18.输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。#includeintmain(){intc;intnword=0;intnspace=0;intnother=0;intnnum=0;while((c=getchar())!=EOF){if((c>='a'&&c<='z')||(c<='Z'&&c>='A')){nword++;}elseif(c>='0'&&c<='9'){nnum++;}elseif(c==''){nspace++;}else{nother++;}}printf("space:%d\n",nspace);printf("num:%d\n",nnum);printf("other:%d\n",nother);printf("word:%d\n",nword);return0;}19.输入一个字串,判断它是否是对称串。如”abcdcba”是对称串,不是。#includeintpanduan(char*s);intmain(){chars[500];printf("pleaseenterastring:\n");scanf("%s",s);panduan(s);return0;}intpanduan(char*s){char*p=s;char*q=s;while(*q!='\0'){q++;}q--;while((q-p)>1){if(*p!=*q){printf("buduichen!\n");return1;}q--;p++;}printf("duichen");return0;}20.随机产生N个大写字母输出,然后统计其中共有多少个元音字符。(设N为50)#include#include#include#defineN10intisyuan(chars);intmain(){chars[N];inti;intcount=0;charzimubiao[]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};srand(time(NULL));for(i=0;i{s[i]=zimubiao[rand()%26];}for(i=0;i{printf("%c",s[i]);}printf("\n");for(i=0;i{if(isyuan(s[i])){count++;}}printf("gongyouyuanyin%dge\n",count);return0;}intisyuan(chars){intj;charyuanyinbiao[]={'A','E','I','O','U'};for(j=0;j<5;j++){if(s==yuanyinbiao[j]){return1;}}return0;}21.找出三位自然数中的所有素数,要求判断x素数用自定义函数data(x)实现。#includeintdata(intx);intmain(){inti;for(i=100;i<=999;i++){if(data(i)){printf("%dshisushu\n",i);}}return0;}//sushufanhui1,bushifanhui0.intdata(intx){intj;for(j=2;j{if((x%j)==0){return0;}}return1;}22.输出n行由“#”组成的矩形,每行“#”的个数为m个,其中n、m由终端(键盘)输入。要求输出m个“#”功能由函数satr(m)函数实现。#includevoidsatr(intm);intm,n;intmain(){printf("qingshurumndezhi:\n");scanf("%d",&m);scanf("%d",&n);satr(m);return0;}voidsatr(m){inti,j;for(i=0;i{for(j=0;j{printf("#");}printf("\n");}}23.若ax2+bx+c=0有实根,则求之。#include#includeintmain(){floata,b,c,disc,x1,x2,p,q;scanf("a=%f,b=%f,c=%f",&a,&b,&c);disc=b*b-4*a*c;if(disc<0){printf("meiyoushigen");}else{p=-b/(2*a);q=sqrt(disc)/(2*a);x1=p+q;x2=p-q;printf("\nx1=%5.2f\nx2=%5.2f\n",x1,x2);}return0;}24.从键盘输入两个字串,判断它们是否相同。#
s[i]=i;
printf("%d\n",s[i]);
for(i=5;i>0;i--)
a[j]=s[i-1];
j++;
printf("%d",a[j-1]);
5.要将5张100元的大钞票,换成等值的50元,20元,10元,5元一张的小钞票,每种面值至少1张,编程求的需要多少张纸币。
#definemoney500
inti,k;
intj,l;
printf("输出结果:
\n");
for(i=50+(money%50);i{for(j=20;(money%50==0)?jj<=i-15;j+=20){for(k=10;k{printf("%d张50%d张20%d张10%d张5\n",(money-i)/50,j/20,k/10,(i-j-k)/5);}}}}6.求n以内(不包括n)同时能被3和7整除的所有自然数之和的平方根s,n从键盘输入。例如若n为1000时,函数值应为:s=153.909064。#include#includemain(){inti;intn=1;intsum=0;printf("输入一个>21的数:");scanf("%d",&n);if(n>21){n--;for(;n>=21;n--){if(n%3==0&&n%7==0){printf("%d",n);sum+=n;i=sqrt(sum);}}printf("\n");}else{printf("输入错误:\n");}}7.一辆卡车违反交通规则,撞人后逃跑。现场有三人目击事件,但都没有记住车号,只记下车号的一些特征。甲说:牌照的前两位数字是相同的;乙说:牌照的后两位数字是相同的,但与前两位不同;丙是数学家,他说:四位的车号刚好是一个整数的平方。请根据以上线索找出车号。#includemain(){inti;intj;inta,b,c,d;for(i=31;i<100;i++){j=i*i;a=j%10;b=(j%100-a)/10;c=(j%1000-a-b)/100;d=j/1000;if((a==b&&c==d)&&a!=c){printf("输出牌号:%d\n",j);}}}8.输入1~10之间的一个数字,输出它对应的英文单词。#include//第八题:#include#includemain(){intq;intt;charm[10]={'a','b','c','d','e','f','g','h','i','j'};//printf("%c",m[2]);printf("请输入1-10\n");scanf("%d",&q);t=q-1;printf("%d对应的字母是:%c\n",q,m[t]);}9.个位数为6且能被3整除但不能被5整除的三位自然数共有多少个,分别是哪些?#include//第九题#include#includemain(){inti;for(i=100;i<1000;i++){if(i%10==6){if(i%3==0){if(i%5!=0){printf("%d\n",i);}}//printf("%d\n",i);//continue;}}}10.输入某年某月某日,判断这一天是这一年的第几天?#include//第十题#include#includemain(){inty,m,d;scanf("%d%d%d",&y,&m,&d);if(y%4==0&y%100!=0|y%400==0){switch(m){case1:printf("是今年的%d天\n",d);break;case2:printf("是今年的%d天\n",d+31);break;case3:printf("是今年的%d天\n",d+31+29);break;case4:printf("是今年的%d天\n",d+31+29+31);break;case5:printf("是今年的%d天\n",d+31+29+31+30);break;case6:printf("是今年的%d天\n",d+31+29+31+30+31);break;case7:printf("是今年的%d天\n",d+31+29+31+30+31+30);break;case8:printf("是今年的%d天\n",d+31+29+31+30+31+31+31);break;case9:printf("是今年的%d天\n",d+31+29+31+30+31+31+31+31);break;case10:printf("是今年的%d天\n",d+31+29+31+30+31+31+31+31+30);break;case11:printf("是今年的%d天\n",d+31+29+31+30+31+31+31+31+30+31);break;case12:printf("是今年的%d天\n",d+31+29+31+30+31+31+31+31+30+31+30);break;}}else{switch(m){case1:printf("是今年的%d天\n",d);break;case2:printf("是今年的%d天\n",d+31);break;case3:printf("是今年的%d天\n",d+31+28);break;case4:printf("是今年的%d天\n",d+31+28+31);break;case5:printf("是今年的%d天\n",d+31+28+31+30);break;case6:printf("是今年的%d天\n",d+31+28+31+30+31);break;case7:printf("是今年的%d天\n",d+31+28+31+30+31+30);break;case8:printf("是今年的%d天\n",d+31+28+31+30+31+31+31);break;case9:printf("是今年的%d天\n",d+31+28+31+30+31+31+31+31);break;case10:printf("是今年的%d天\n",d+31+28+31+30+31+31+31+31+30);break;case11:printf("是今年的%d天\n",d+31+28+31+30+31+31+31+31+30+31);break;case12:printf("是今年的%d天\n",d+31+28+31+30+31+31+31+31+30+31+30);break;}}}11.两个乒乓球队进行比赛,各出三人。甲队为a,b,c三人,乙队为x,y,z三人。已抽签决定比赛名单。有人向队员打听比赛的名单。a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单。#includeintmain(){chari;charj;chark;for(i='x';i<='z';i++){for(j='x';j<='z';j++){if(i!=j){for(k='x';k<='y';k++){if(i!=k&&j!=k){if(i!='x'&&k!='x'&&k!='z'){printf("a--->%c\nb--->%c\nc--->%c",i,j,k);}}}}}}return0;}12.有5个人坐在一起,问第五个人多少岁?他说比第4个人大2岁。问第4个人岁数,他说比第3个人大2岁。问第三个人,又说比第2人大两岁。问第2个人,说比第一个人大两岁。最后问第一个人,他说是10岁。请问第五个人多大?#includeintfac(intn);intmain(){inta=5;printf("di5gerendedesuishushi%d\n",fac(a));return0;}intfac(intn){if(n==1){return10;}else{return2+fac(n-1);}}13.输入某三角形的三个边的长度,判断出这是个什么三角形(等腰、等边、任意,或不能构成)。#includeintmain(){inta,b,c;printf("pleaseenterabc\n");scanf("%d%d%d",&a,&b,&c);//printf("%d\n%d\n%d\n",a,b,c);if((a+b<=c)||(a-b>=c)){printf("bunenggouchengsanjiaoxing\n");}elseif(a==b&&b==c){printf("dengbiansanjiaoxing\n");}return0;}14.输入10个数,分别统计其中正数、负数、零的个数。#include"stdio.h"main(){inta[10],i;s1=0;s2=0;s3=0;printf("请输入10个数:\n");for(i=0;i<10;i++)scanf("%d",&a[i]);for(i=0;i<10;i++){if(a[i]<0)s1++;if(a[i]==0)s2++;if(a[i]>0)s3++;}printf("负数为%d个,零为%d个,正数为%d个",s1,s2,s3);}15.先随机产生N个三位自然数输出,然后再输出其中同时是3、5、7倍数的数。(设N为100)#include"stdio.h"#include"time.h"main(){inta,c,n;srand((unsigned)time(NULL));for(a=0;a<100;a++){c=rand()%1000;if(c>=100&&c%3==0&&c%5==0&&c%7==0){printf("%d\n",c);}}}16.用for编程找出100~200中的完全平方数。#includeintmain(){inti=10;intb;for(i=10;i<=15;i++){b=i*i;if(b<=200&&b>=100){printf("%d\n",b);}}return0;}17.从终端输入三个正实数,判断这三个数能否构成直角三角形。#include"stdio.h"main(){inta,b,c;printf("请输入三个正实数:\n");scanf("%d%d%d",&a,&b,&c);if(a*a+b*b==c*c)printf("这是直角三角形!\n");elseprintf("不构成直角三角形!\n");}18.输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。#includeintmain(){intc;intnword=0;intnspace=0;intnother=0;intnnum=0;while((c=getchar())!=EOF){if((c>='a'&&c<='z')||(c<='Z'&&c>='A')){nword++;}elseif(c>='0'&&c<='9'){nnum++;}elseif(c==''){nspace++;}else{nother++;}}printf("space:%d\n",nspace);printf("num:%d\n",nnum);printf("other:%d\n",nother);printf("word:%d\n",nword);return0;}19.输入一个字串,判断它是否是对称串。如”abcdcba”是对称串,不是。#includeintpanduan(char*s);intmain(){chars[500];printf("pleaseenterastring:\n");scanf("%s",s);panduan(s);return0;}intpanduan(char*s){char*p=s;char*q=s;while(*q!='\0'){q++;}q--;while((q-p)>1){if(*p!=*q){printf("buduichen!\n");return1;}q--;p++;}printf("duichen");return0;}20.随机产生N个大写字母输出,然后统计其中共有多少个元音字符。(设N为50)#include#include#include#defineN10intisyuan(chars);intmain(){chars[N];inti;intcount=0;charzimubiao[]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};srand(time(NULL));for(i=0;i{s[i]=zimubiao[rand()%26];}for(i=0;i{printf("%c",s[i]);}printf("\n");for(i=0;i{if(isyuan(s[i])){count++;}}printf("gongyouyuanyin%dge\n",count);return0;}intisyuan(chars){intj;charyuanyinbiao[]={'A','E','I','O','U'};for(j=0;j<5;j++){if(s==yuanyinbiao[j]){return1;}}return0;}21.找出三位自然数中的所有素数,要求判断x素数用自定义函数data(x)实现。#includeintdata(intx);intmain(){inti;for(i=100;i<=999;i++){if(data(i)){printf("%dshisushu\n",i);}}return0;}//sushufanhui1,bushifanhui0.intdata(intx){intj;for(j=2;j{if((x%j)==0){return0;}}return1;}22.输出n行由“#”组成的矩形,每行“#”的个数为m个,其中n、m由终端(键盘)输入。要求输出m个“#”功能由函数satr(m)函数实现。#includevoidsatr(intm);intm,n;intmain(){printf("qingshurumndezhi:\n");scanf("%d",&m);scanf("%d",&n);satr(m);return0;}voidsatr(m){inti,j;for(i=0;i{for(j=0;j{printf("#");}printf("\n");}}23.若ax2+bx+c=0有实根,则求之。#include#includeintmain(){floata,b,c,disc,x1,x2,p,q;scanf("a=%f,b=%f,c=%f",&a,&b,&c);disc=b*b-4*a*c;if(disc<0){printf("meiyoushigen");}else{p=-b/(2*a);q=sqrt(disc)/(2*a);x1=p+q;x2=p-q;printf("\nx1=%5.2f\nx2=%5.2f\n",x1,x2);}return0;}24.从键盘输入两个字串,判断它们是否相同。#
for(j=20;(money%50==0)?
jj<=i-15;j+=20){for(k=10;k{printf("%d张50%d张20%d张10%d张5\n",(money-i)/50,j/20,k/10,(i-j-k)/5);}}}}6.求n以内(不包括n)同时能被3和7整除的所有自然数之和的平方根s,n从键盘输入。例如若n为1000时,函数值应为:s=153.909064。#include#includemain(){inti;intn=1;intsum=0;printf("输入一个>21的数:");scanf("%d",&n);if(n>21){n--;for(;n>=21;n--){if(n%3==0&&n%7==0){printf("%d",n);sum+=n;i=sqrt(sum);}}printf("\n");}else{printf("输入错误:\n");}}7.一辆卡车违反交通规则,撞人后逃跑。现场有三人目击事件,但都没有记住车号,只记下车号的一些特征。甲说:牌照的前两位数字是相同的;乙说:牌照的后两位数字是相同的,但与前两位不同;丙是数学家,他说:四位的车号刚好是一个整数的平方。请根据以上线索找出车号。#includemain(){inti;intj;inta,b,c,d;for(i=31;i<100;i++){j=i*i;a=j%10;b=(j%100-a)/10;c=(j%1000-a-b)/100;d=j/1000;if((a==b&&c==d)&&a!=c){printf("输出牌号:%d\n",j);}}}8.输入1~10之间的一个数字,输出它对应的英文单词。#include//第八题:#include#includemain(){intq;intt;charm[10]={'a','b','c','d','e','f','g','h','i','j'};//printf("%c",m[2]);printf("请输入1-10\n");scanf("%d",&q);t=q-1;printf("%d对应的字母是:%c\n",q,m[t]);}9.个位数为6且能被3整除但不能被5整除的三位自然数共有多少个,分别是哪些?#include//第九题#include#includemain(){inti;for(i=100;i<1000;i++){if(i%10==6){if(i%3==0){if(i%5!=0){printf("%d\n",i);}}//printf("%d\n",i);//continue;}}}10.输入某年某月某日,判断这一天是这一年的第几天?#include//第十题#include#includemain(){inty,m,d;scanf("%d%d%d",&y,&m,&d);if(y%4==0&y%100!=0|y%400==0){switch(m){case1:printf("是今年的%d天\n",d);break;case2:printf("是今年的%d天\n",d+31);break;case3:printf("是今年的%d天\n",d+31+29);break;case4:printf("是今年的%d天\n",d+31+29+31);break;case5:printf("是今年的%d天\n",d+31+29+31+30);break;case6:printf("是今年的%d天\n",d+31+29+31+30+31);break;case7:printf("是今年的%d天\n",d+31+29+31+30+31+30);break;case8:printf("是今年的%d天\n",d+31+29+31+30+31+31+31);break;case9:printf("是今年的%d天\n",d+31+29+31+30+31+31+31+31);break;case10:printf("是今年的%d天\n",d+31+29+31+30+31+31+31+31+30);break;case11:printf("是今年的%d天\n",d+31+29+31+30+31+31+31+31+30+31);break;case12:printf("是今年的%d天\n",d+31+29+31+30+31+31+31+31+30+31+30);break;}}else{switch(m){case1:printf("是今年的%d天\n",d);break;case2:printf("是今年的%d天\n",d+31);break;case3:printf("是今年的%d天\n",d+31+28);break;case4:printf("是今年的%d天\n",d+31+28+31);break;case5:printf("是今年的%d天\n",d+31+28+31+30);break;case6:printf("是今年的%d天\n",d+31+28+31+30+31);break;case7:printf("是今年的%d天\n",d+31+28+31+30+31+30);break;case8:printf("是今年的%d天\n",d+31+28+31+30+31+31+31);break;case9:printf("是今年的%d天\n",d+31+28+31+30+31+31+31+31);break;case10:printf("是今年的%d天\n",d+31+28+31+30+31+31+31+31+30);break;case11:printf("是今年的%d天\n",d+31+28+31+30+31+31+31+31+30+31);break;case12:printf("是今年的%d天\n",d+31+28+31+30+31+31+31+31+30+31+30);break;}}}11.两个乒乓球队进行比赛,各出三人。甲队为a,b,c三人,乙队为x,y,z三人。已抽签决定比赛名单。有人向队员打听比赛的名单。a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单。#includeintmain(){chari;charj;chark;for(i='x';i<='z';i++){for(j='x';j<='z';j++){if(i!=j){for(k='x';k<='y';k++){if(i!=k&&j!=k){if(i!='x'&&k!='x'&&k!='z'){printf("a--->%c\nb--->%c\nc--->%c",i,j,k);}}}}}}return0;}12.有5个人坐在一起,问第五个人多少岁?他说比第4个人大2岁。问第4个人岁数,他说比第3个人大2岁。问第三个人,又说比第2人大两岁。问第2个人,说比第一个人大两岁。最后问第一个人,他说是10岁。请问第五个人多大?#includeintfac(intn);intmain(){inta=5;printf("di5gerendedesuishushi%d\n",fac(a));return0;}intfac(intn){if(n==1){return10;}else{return2+fac(n-1);}}13.输入某三角形的三个边的长度,判断出这是个什么三角形(等腰、等边、任意,或不能构成)。#includeintmain(){inta,b,c;printf("pleaseenterabc\n");scanf("%d%d%d",&a,&b,&c);//printf("%d\n%d\n%d\n",a,b,c);if((a+b<=c)||(a-b>=c)){printf("bunenggouchengsanjiaoxing\n");}elseif(a==b&&b==c){printf("dengbiansanjiaoxing\n");}return0;}14.输入10个数,分别统计其中正数、负数、零的个数。#include"stdio.h"main(){inta[10],i;s1=0;s2=0;s3=0;printf("请输入10个数:\n");for(i=0;i<10;i++)scanf("%d",&a[i]);for(i=0;i<10;i++){if(a[i]<0)s1++;if(a[i]==0)s2++;if(a[i]>0)s3++;}printf("负数为%d个,零为%d个,正数为%d个",s1,s2,s3);}15.先随机产生N个三位自然数输出,然后再输出其中同时是3、5、7倍数的数。(设N为100)#include"stdio.h"#include"time.h"main(){inta,c,n;srand((unsigned)time(NULL));for(a=0;a<100;a++){c=rand()%1000;if(c>=100&&c%3==0&&c%5==0&&c%7==0){printf("%d\n",c);}}}16.用for编程找出100~200中的完全平方数。#includeintmain(){inti=10;intb;for(i=10;i<=15;i++){b=i*i;if(b<=200&&b>=100){printf("%d\n",b);}}return0;}17.从终端输入三个正实数,判断这三个数能否构成直角三角形。#include"stdio.h"main(){inta,b,c;printf("请输入三个正实数:\n");scanf("%d%d%d",&a,&b,&c);if(a*a+b*b==c*c)printf("这是直角三角形!\n");elseprintf("不构成直角三角形!\n");}18.输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。#includeintmain(){intc;intnword=0;intnspace=0;intnother=0;intnnum=0;while((c=getchar())!=EOF){if((c>='a'&&c<='z')||(c<='Z'&&c>='A')){nword++;}elseif(c>='0'&&c<='9'){nnum++;}elseif(c==''){nspace++;}else{nother++;}}printf("space:%d\n",nspace);printf("num:%d\n",nnum);printf("other:%d\n",nother);printf("word:%d\n",nword);return0;}19.输入一个字串,判断它是否是对称串。如”abcdcba”是对称串,不是。#includeintpanduan(char*s);intmain(){chars[500];printf("pleaseenterastring:\n");scanf("%s",s);panduan(s);return0;}intpanduan(char*s){char*p=s;char*q=s;while(*q!='\0'){q++;}q--;while((q-p)>1){if(*p!=*q){printf("buduichen!\n");return1;}q--;p++;}printf("duichen");return0;}20.随机产生N个大写字母输出,然后统计其中共有多少个元音字符。(设N为50)#include#include#include#defineN10intisyuan(chars);intmain(){chars[N];inti;intcount=0;charzimubiao[]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};srand(time(NULL));for(i=0;i{s[i]=zimubiao[rand()%26];}for(i=0;i{printf("%c",s[i]);}printf("\n");for(i=0;i{if(isyuan(s[i])){count++;}}printf("gongyouyuanyin%dge\n",count);return0;}intisyuan(chars){intj;charyuanyinbiao[]={'A','E','I','O','U'};for(j=0;j<5;j++){if(s==yuanyinbiao[j]){return1;}}return0;}21.找出三位自然数中的所有素数,要求判断x素数用自定义函数data(x)实现。#includeintdata(intx);intmain(){inti;for(i=100;i<=999;i++){if(data(i)){printf("%dshisushu\n",i);}}return0;}//sushufanhui1,bushifanhui0.intdata(intx){intj;for(j=2;j{if((x%j)==0){return0;}}return1;}22.输出n行由“#”组成的矩形,每行“#”的个数为m个,其中n、m由终端(键盘)输入。要求输出m个“#”功能由函数satr(m)函数实现。#includevoidsatr(intm);intm,n;intmain(){printf("qingshurumndezhi:\n");scanf("%d",&m);scanf("%d",&n);satr(m);return0;}voidsatr(m){inti,j;for(i=0;i{for(j=0;j{printf("#");}printf("\n");}}23.若ax2+bx+c=0有实根,则求之。#include#includeintmain(){floata,b,c,disc,x1,x2,p,q;scanf("a=%f,b=%f,c=%f",&a,&b,&c);disc=b*b-4*a*c;if(disc<0){printf("meiyoushigen");}else{p=-b/(2*a);q=sqrt(disc)/(2*a);x1=p+q;x2=p-q;printf("\nx1=%5.2f\nx2=%5.2f\n",x1,x2);}return0;}24.从键盘输入两个字串,判断它们是否相同。#
j<=i-15;j+=20)
for(k=10;k{printf("%d张50%d张20%d张10%d张5\n",(money-i)/50,j/20,k/10,(i-j-k)/5);}}}}6.求n以内(不包括n)同时能被3和7整除的所有自然数之和的平方根s,n从键盘输入。例如若n为1000时,函数值应为:s=153.909064。#include#includemain(){inti;intn=1;intsum=0;printf("输入一个>21的数:");scanf("%d",&n);if(n>21){n--;for(;n>=21;n--){if(n%3==0&&n%7==0){printf("%d",n);sum+=n;i=sqrt(sum);}}printf("\n");}else{printf("输入错误:\n");}}7.一辆卡车违反交通规则,撞人后逃跑。现场有三人目击事件,但都没有记住车号,只记下车号的一些特征。甲说:牌照的前两位数字是相同的;乙说:牌照的后两位数字是相同的,但与前两位不同;丙是数学家,他说:四位的车号刚好是一个整数的平方。请根据以上线索找出车号。#includemain(){inti;intj;inta,b,c,d;for(i=31;i<100;i++){j=i*i;a=j%10;b=(j%100-a)/10;c=(j%1000-a-b)/100;d=j/1000;if((a==b&&c==d)&&a!=c){printf("输出牌号:%d\n",j);}}}8.输入1~10之间的一个数字,输出它对应的英文单词。#include//第八题:#include#includemain(){intq;intt;charm[10]={'a','b','c','d','e','f','g','h','i','j'};//printf("%c",m[2]);printf("请输入1-10\n");scanf("%d",&q);t=q-1;printf("%d对应的字母是:%c\n",q,m[t]);}9.个位数为6且能被3整除但不能被5整除的三位自然数共有多少个,分别是哪些?#include//第九题#include#includemain(){inti;for(i=100;i<1000;i++){if(i%10==6){if(i%3==0){if(i%5!=0){printf("%d\n",i);}}//printf("%d\n",i);//continue;}}}10.输入某年某月某日,判断这一天是这一年的第几天?#include//第十题#include#includemain(){inty,m,d;scanf("%d%d%d",&y,&m,&d);if(y%4==0&y%100!=0|y%400==0){switch(m){case1:printf("是今年的%d天\n",d);break;case2:printf("是今年的%d天\n",d+31);break;case3:printf("是今年的%d天\n",d+31+29);break;case4:printf("是今年的%d天\n",d+31+29+31);break;case5:printf("是今年的%d天\n",d+31+29+31+30);break;case6:printf("是今年的%d天\n",d+31+29+31+30+31);break;case7:printf("是今年的%d天\n",d+31+29+31+30+31+30);break;case8:printf("是今年的%d天\n",d+31+29+31+30+31+31+31);break;case9:printf("是今年的%d天\n",d+31+29+31+30+31+31+31+31);break;case10:printf("是今年的%d天\n",d+31+29+31+30+31+31+31+31+30);break;case11:printf("是今年的%d天\n",d+31+29+31+30+31+31+31+31+30+31);break;case12:printf("是今年的%d天\n",d+31+29+31+30+31+31+31+31+30+31+30);break;}}else{switch(m){case1:printf("是今年的%d天\n",d);break;case2:printf("是今年的%d天\n",d+31);break;case3:printf("是今年的%d天\n",d+31+28);break;case4:printf("是今年的%d天\n",d+31+28+31);break;case5:printf("是今年的%d天\n",d+31+28+31+30);break;case6:printf("是今年的%d天\n",d+31+28+31+30+31);break;case7:printf("是今年的%d天\n",d+31+28+31+30+31+30);break;case8:printf("是今年的%d天\n",d+31+28+31+30+31+31+31);break;case9:printf("是今年的%d天\n",d+31+28+31+30+31+31+31+31);break;case10:printf("是今年的%d天\n",d+31+28+31+30+31+31+31+31+30);break;case11:printf("是今年的%d天\n",d+31+28+31+30+31+31+31+31+30+31);break;case12:printf("是今年的%d天\n",d+31+28+31+30+31+31+31+31+30+31+30);break;}}}11.两个乒乓球队进行比赛,各出三人。甲队为a,b,c三人,乙队为x,y,z三人。已抽签决定比赛名单。有人向队员打听比赛的名单。a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单。#includeintmain(){chari;charj;chark;for(i='x';i<='z';i++){for(j='x';j<='z';j++){if(i!=j){for(k='x';k<='y';k++){if(i!=k&&j!=k){if(i!='x'&&k!='x'&&k!='z'){printf("a--->%c\nb--->%c\nc--->%c",i,j,k);}}}}}}return0;}12.有5个人坐在一起,问第五个人多少岁?他说比第4个人大2岁。问第4个人岁数,他说比第3个人大2岁。问第三个人,又说比第2人大两岁。问第2个人,说比第一个人大两岁。最后问第一个人,他说是10岁。请问第五个人多大?#includeintfac(intn);intmain(){inta=5;printf("di5gerendedesuishushi%d\n",fac(a));return0;}intfac(intn){if(n==1){return10;}else{return2+fac(n-1);}}13.输入某三角形的三个边的长度,判断出这是个什么三角形(等腰、等边、任意,或不能构成)。#includeintmain(){inta,b,c;printf("pleaseenterabc\n");scanf("%d%d%d",&a,&b,&c);//printf("%d\n%d\n%d\n",a,b,c);if((a+b<=c)||(a-b>=c)){printf("bunenggouchengsanjiaoxing\n");}elseif(a==b&&b==c){printf("dengbiansanjiaoxing\n");}return0;}14.输入10个数,分别统计其中正数、负数、零的个数。#include"stdio.h"main(){inta[10],i;s1=0;s2=0;s3=0;printf("请输入10个数:\n");for(i=0;i<10;i++)scanf("%d",&a[i]);for(i=0;i<10;i++){if(a[i]<0)s1++;if(a[i]==0)s2++;if(a[i]>0)s3++;}printf("负数为%d个,零为%d个,正数为%d个",s1,s2,s3);}15.先随机产生N个三位自然数输出,然后再输出其中同时是3、5、7倍数的数。(设N为100)#include"stdio.h"#include"time.h"main(){inta,c,n;srand((unsigned)time(NULL));for(a=0;a<100;a++){c=rand()%1000;if(c>=100&&c%3==0&&c%5==0&&c%7==0){printf("%d\n",c);}}}16.用for编程找出100~200中的完全平方数。#includeintmain(){inti=10;intb;for(i=10;i<=15;i++){b=i*i;if(b<=200&&b>=100){printf("%d\n",b);}}return0;}17.从终端输入三个正实数,判断这三个数能否构成直角三角形。#include"stdio.h"main(){inta,b,c;printf("请输入三个正实数:\n");scanf("%d%d%d",&a,&b,&c);if(a*a+b*b==c*c)printf("这是直角三角形!\n");elseprintf("不构成直角三角形!\n");}18.输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。#includeintmain(){intc;intnword=0;intnspace=0;intnother=0;intnnum=0;while((c=getchar())!=EOF){if((c>='a'&&c<='z')||(c<='Z'&&c>='A')){nword++;}elseif(c>='0'&&c<='9'){nnum++;}elseif(c==''){nspace++;}else{nother++;}}printf("space:%d\n",nspace);printf("num:%d\n",nnum);printf("other:%d\n",nother);printf("word:%d\n",nword);return0;}19.输入一个字串,判断它是否是对称串。如”abcdcba”是对称串,不是。#includeintpanduan(char*s);intmain(){chars[500];printf("pleaseenterastring:\n");scanf("%s",s);panduan(s);return0;}intpanduan(char*s){char*p=s;char*q=s;while(*q!='\0'){q++;}q--;while((q-p)>1){if(*p!=*q){printf("buduichen!\n");return1;}q--;p++;}printf("duichen");return0;}20.随机产生N个大写字母输出,然后统计其中共有多少个元音字符。(设N为50)#include#include#include#defineN10intisyuan(chars);intmain(){chars[N];inti;intcount=0;charzimubiao[]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};srand(time(NULL));for(i=0;i{s[i]=zimubiao[rand()%26];}for(i=0;i{printf("%c",s[i]);}printf("\n");for(i=0;i{if(isyuan(s[i])){count++;}}printf("gongyouyuanyin%dge\n",count);return0;}intisyuan(chars){intj;charyuanyinbiao[]={'A','E','I','O','U'};for(j=0;j<5;j++){if(s==yuanyinbiao[j]){return1;}}return0;}21.找出三位自然数中的所有素数,要求判断x素数用自定义函数data(x)实现。#includeintdata(intx);intmain(){inti;for(i=100;i<=999;i++){if(data(i)){printf("%dshisushu\n",i);}}return0;}//sushufanhui1,bushifanhui0.intdata(intx){intj;for(j=2;j{if((x%j)==0){return0;}}return1;}22.输出n行由“#”组成的矩形,每行“#”的个数为m个,其中n、m由终端(键盘)输入。要求输出m个“#”功能由函数satr(m)函数实现。#includevoidsatr(intm);intm,n;intmain(){printf("qingshurumndezhi:\n");scanf("%d",&m);scanf("%d",&n);satr(m);return0;}voidsatr(m){inti,j;for(i=0;i{for(j=0;j{printf("#");}printf("\n");}}23.若ax2+bx+c=0有实根,则求之。#include#includeintmain(){floata,b,c,disc,x1,x2,p,q;scanf("a=%f,b=%f,c=%f",&a,&b,&c);disc=b*b-4*a*c;if(disc<0){printf("meiyoushigen");}else{p=-b/(2*a);q=sqrt(disc)/(2*a);x1=p+q;x2=p-q;printf("\nx1=%5.2f\nx2=%5.2f\n",x1,x2);}return0;}24.从键盘输入两个字串,判断它们是否相同。#
{printf("%d张50%d张20%d张10%d张5\n",(money-i)/50,j/20,k/10,(i-j-k)/5);
6.求n以内(不包括n)同时能被3和7整除的所有自然数之和的平方根s,n从键盘输入。
例如若n为1000时,函数值应为:
s=153.909064。
intn=1;
printf("输入一个>21的数:
if(n>21)
{n--;
for(;n>=21;n--)
if(n%3==0&&n%7==0)
printf("%d",n);
sum+=n;
i=sqrt(sum);
printf("\n");
else{
printf("输入错误:
\n");}
7.一辆卡车违反交通规则,撞人后逃跑。
现场有三人目击事件,但都没有记住车号,只记下车号的一些特征。
甲说:
牌照的前两位数字是相同的;乙说:
牌照的后两位数字是相同的,但与前两位不同;丙是数学家,他说:
四位的车号刚好是一个整数的平方。
请根据以上线索找出车号。
intj;
inta,b,c,d;
for(i=31;i<100;i++)
j=i*i;
a=j%10;
b=(j%100-a)/10;
c=(j%1000-a-b)/100;
d=j/1000;
if((a==b&&c==d)&&a!
=c)
{printf("输出牌号:
%d\n",j);}
8.输入1~10之间的一个数字,输出它对应的英文单词。
#include//第八题:
intq;
intt;
charm[10]={'a','b','c','d','e','f','g','h','i','j'};
//printf("%c",m[2]);
printf("请输入1-10\n");
scanf("%d",&q);
t=q-1;
printf("%d对应的字母是:
%c\n",q,m[t]);
9.个位数为6且能被3整除但不能被5整除的三位自然数共有多少个,分别是哪些?
#include//第九题
for(i=100;i<1000;i++)
if(i%10==6)
if(i%3==0)
if(i%5!
=0)
printf("%d\n",i);
}//printf("%d\n",i);
//continue;
10.输入某年某月某日,判断这一天是这一年的第几天?
#include//第十题
inty,m,d;
scanf("%d%d%d",&y,&m,&d);
if(y%4==0&y%100!
=0|y%400==0){
switch(m){
case1:
printf("是今年的%d天\n",d);
break;
case2:
printf("是今年的%d天\n",d+31);
case3:
printf("是今年的%d天\n",d+31+29);
case4:
printf("是今年的%d天\n",d+31+29+31);
case5:
printf("是今年的%d天\n",d+31+29+31+30);
case6:
printf("是今年的%d天\n",d+31+29+31+30+31);
case7:
printf("是今年的%d天\n",d+31+29+31+30+31+30);
case8:
printf("是今年的%d天\n",d+31+29+31+30+31+31+31);
case9:
printf("是今年的%d天\n",d+31+29+31+30+31+31+31+31);
case10:
printf("是今年的%d天\n",d+31+29+31+30+31+31+31+31+30);
case11:
printf("是今年的%d天\n",d+31+29+31+30+31+31+31+31+30
+31);
case12:
+31+30);
}else{
printf("是今年的%d天\n",d+31+28);
printf("是今年的%d天\n",d+31+28+31);
printf("是今年的%d天\n",d+31+28+31+30);
printf("是今年的%d天\n",d+31+28+31+30+31);
printf("是今年的%d天\n",d+31+28+31+30+31+30);
printf("是今年的%d天\n",d+31+28+31+30+31+31+31);
printf("是今年的%d天\n",d+31+28+31+30+31+31+31+31);
printf("是今年的%d天\n",d+31+28+31+30+31+31+31+31+30);
printf("是今年的%d天\n",d+31+28+31+30+31+31+31+31+30
11.两个乒乓球队进行比赛,各出三人。
甲队为a,b,c三人,乙队为x,y,z三人。
已抽签决定
比赛名单。
有人向队员打听比赛的名单。
a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单。
intmain(){
chari;
charj;
chark;
for(i='x';i<='z';i++)
for(j='x';j<='z';j++)
if(i!
=j)
for(k='x';k<='y';k++)
=k&&j!
=k)
='x'&&k!
='z')
printf("a--->%c\nb--->%c\nc--->%c",i,j,k);
return0;
12.有5个人坐在一起,问第五个人多少岁?
他说比第4个人大2岁。
问第4个人岁数,他说比第3个人大2岁。
问第三个人,又说比第2人大两岁。
问第2个人,说比第一个人大两岁。
最后问第一个人,他说是10岁。
请问第五个人多大?
intfac(intn);
intmain()
inta=5;
printf("di5gerendedesuishushi%d\n",fac(a));
intfac(intn)
if(n==1)
return10;
else
return2+fac(n-1);
13.输入某三角形的三个边的长度,判断出这是个什么三角形(等腰、等边、任意,或不能构成)。
inta,b,c;
printf("pleaseenterabc\n");
scanf("%d%d%d",&a,&b,&c);
//printf("%d\n%d\n%d\n",a,b,c);
if((a+b<=c)||(a-b>=c))
printf("bunenggouchengsanjiaoxing\n");
elseif(a==b&&b==c)
printf("dengbiansanjiaoxing\n");
14.输入10个数,分别统计其中正数、负数、零的个数。
#include"stdio.h"
inta[10],i;
s1=0;
s2=0;
s3=0;
printf("请输入10个数:
for(i=0;i<10;i++)
scanf("%d",&a[i]);
if(a[i]<0)
s1++;
if(a[i]==0)
s2++;
if(a[i]>0)
s3++;
printf("负数为%d个,零为%d个,正数为%d个",s1,s2,s3);
15.先随机产生N个三位自然数输出,然后再输出其中同时是3、5、7倍数的数。
(设N为100)
#include"time.h"
inta,c,n;
srand((unsigned)time(NULL));
for(a=0;a<100;a++)
c=rand()%1000;
if(c>=100&&c%3==0&&c%5==0&&c%7==0)
printf("%d\n",c);
16.用for编程找出100~200中的完全平方数。
inti=10;
intb;
for(i=10;i<=15;i++)
b=i*i;
if(b<=200&&b>=100)
printf("%d\n",b);
17.从终端输入三个正实数,判断这三个数能否构成直角三角形。
printf("请输入三个正实数:
if(a*a+b*b==c*c)
printf("这是直角三角形!
printf("不构成直角三角形!
18.输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
intc;
intnword=0;
intnspace=0;
intnother=0;
intnnum=0;
while((c=getchar())!
=EOF)
if((c>='a'&&c<='z')||(c<='Z'&&c>='A'))
nword++;
elseif(c>='0'&&c<='9')
nnum++;
elseif(c=='')
nspace++;
nother++;
printf("space:
%d\n",nspace);
printf("num:
%d\n",nnum);
printf("other:
%d\n",nother);
printf("word:
%d\n",nword);
19.输入一个字串,判断它是否是对称串。
如”abcdcba”是对称串,不是。
intpanduan(char*s);
chars[500];
printf("pleaseenterastring:
scanf("%s",s);
panduan(s);
intpanduan(char*s)
char*p=s;
char*q=s;
while(*q!
='\0')
q++;
q--;
while((q-p)>1)
if(*p!
=*q)
printf("buduichen!
return1;
p++;
printf("duichen");
20.随机产生N个大写字母输出,然后统计其中共有多少个元音字符。
(设N为50)
#defineN10
intisyuan(chars);
chars[N];
intcount=0;
charzimubiao[]={'A','B','C','D','E','F','G',
'H','I','J','K','L','M','N','O','P','Q','R','S','T',
'U','V','W','X','Y','Z'};
srand(time(NULL));
for(i=0;i{s[i]=zimubiao[rand()%26];}for(i=0;i{printf("%c",s[i]);}printf("\n");for(i=0;i{if(isyuan(s[i])){count++;}}printf("gongyouyuanyin%dge\n",count);return0;}intisyuan(chars){intj;charyuanyinbiao[]={'A','E','I','O','U'};for(j=0;j<5;j++){if(s==yuanyinbiao[j]){return1;}}return0;}21.找出三位自然数中的所有素数,要求判断x素数用自定义函数data(x)实现。#includeintdata(intx);intmain(){inti;for(i=100;i<=999;i++){if(data(i)){printf("%dshisushu\n",i);}}return0;}//sushufanhui1,bushifanhui0.intdata(intx){intj;for(j=2;j{if((x%j)==0){return0;}}return1;}22.输出n行由“#”组成的矩形,每行“#”的个数为m个,其中n、m由终端(键盘)输入。要求输出m个“#”功能由函数satr(m)函数实现。#includevoidsatr(intm);intm,n;intmain(){printf("qingshurumndezhi:\n");scanf("%d",&m);scanf("%d",&n);satr(m);return0;}voidsatr(m){inti,j;for(i=0;i{for(j=0;j{printf("#");}printf("\n");}}23.若ax2+bx+c=0有实根,则求之。#include#includeintmain(){floata,b,c,disc,x1,x2,p,q;scanf("a=%f,b=%f,c=%f",&a,&b,&c);disc=b*b-4*a*c;if(disc<0){printf("meiyoushigen");}else{p=-b/(2*a);q=sqrt(disc)/(2*a);x1=p+q;x2=p-q;printf("\nx1=%5.2f\nx2=%5.2f\n",x1,x2);}return0;}24.从键盘输入两个字串,判断它们是否相同。#
s[i]=zimubiao[rand()%26];
for(i=0;i{printf("%c",s[i]);}printf("\n");for(i=0;i{if(isyuan(s[i])){count++;}}printf("gongyouyuanyin%dge\n",count);return0;}intisyuan(chars){intj;charyuanyinbiao[]={'A','E','I','O','U'};for(j=0;j<5;j++){if(s==yuanyinbiao[j]){return1;}}return0;}21.找出三位自然数中的所有素数,要求判断x素数用自定义函数data(x)实现。#includeintdata(intx);intmain(){inti;for(i=100;i<=999;i++){if(data(i)){printf("%dshisushu\n",i);}}return0;}//sushufanhui1,bushifanhui0.intdata(intx){intj;for(j=2;j{if((x%j)==0){return0;}}return1;}22.输出n行由“#”组成的矩形,每行“#”的个数为m个,其中n、m由终端(键盘)输入。要求输出m个“#”功能由函数satr(m)函数实现。#includevoidsatr(intm);intm,n;intmain(){printf("qingshurumndezhi:\n");scanf("%d",&m);scanf("%d",&n);satr(m);return0;}voidsatr(m){inti,j;for(i=0;i{for(j=0;j{printf("#");}printf("\n");}}23.若ax2+bx+c=0有实根,则求之。#include#includeintmain(){floata,b,c,disc,x1,x2,p,q;scanf("a=%f,b=%f,c=%f",&a,&b,&c);disc=b*b-4*a*c;if(disc<0){printf("meiyoushigen");}else{p=-b/(2*a);q=sqrt(disc)/(2*a);x1=p+q;x2=p-q;printf("\nx1=%5.2f\nx2=%5.2f\n",x1,x2);}return0;}24.从键盘输入两个字串,判断它们是否相同。#
printf("%c",s[i]);
for(i=0;i{if(isyuan(s[i])){count++;}}printf("gongyouyuanyin%dge\n",count);return0;}intisyuan(chars){intj;charyuanyinbiao[]={'A','E','I','O','U'};for(j=0;j<5;j++){if(s==yuanyinbiao[j]){return1;}}return0;}21.找出三位自然数中的所有素数,要求判断x素数用自定义函数data(x)实现。#includeintdata(intx);intmain(){inti;for(i=100;i<=999;i++){if(data(i)){printf("%dshisushu\n",i);}}return0;}//sushufanhui1,bushifanhui0.intdata(intx){intj;for(j=2;j{if((x%j)==0){return0;}}return1;}22.输出n行由“#”组成的矩形,每行“#”的个数为m个,其中n、m由终端(键盘)输入。要求输出m个“#”功能由函数satr(m)函数实现。#includevoidsatr(intm);intm,n;intmain(){printf("qingshurumndezhi:\n");scanf("%d",&m);scanf("%d",&n);satr(m);return0;}voidsatr(m){inti,j;for(i=0;i{for(j=0;j{printf("#");}printf("\n");}}23.若ax2+bx+c=0有实根,则求之。#include#includeintmain(){floata,b,c,disc,x1,x2,p,q;scanf("a=%f,b=%f,c=%f",&a,&b,&c);disc=b*b-4*a*c;if(disc<0){printf("meiyoushigen");}else{p=-b/(2*a);q=sqrt(disc)/(2*a);x1=p+q;x2=p-q;printf("\nx1=%5.2f\nx2=%5.2f\n",x1,x2);}return0;}24.从键盘输入两个字串,判断它们是否相同。#
if(isyuan(s[i]))
count++;
printf("gongyouyuanyin%dge\n",count);
intisyuan(chars)
charyuanyinbiao[]={'A','E','I','O','U'};
for(j=0;j<5;j++)
if(s==yuanyinbiao[j])
21.找出三位自然数中的所有素数,要求判断x素数用自定义函数data(x)实现。
intdata(intx);
for(i=100;i<=999;i++)
if(data(i))
printf("%dshisushu\n",i);
//sushufanhui1,bushifanhui0.
intdata(intx)
for(j=2;j{if((x%j)==0){return0;}}return1;}22.输出n行由“#”组成的矩形,每行“#”的个数为m个,其中n、m由终端(键盘)输入。要求输出m个“#”功能由函数satr(m)函数实现。#includevoidsatr(intm);intm,n;intmain(){printf("qingshurumndezhi:\n");scanf("%d",&m);scanf("%d",&n);satr(m);return0;}voidsatr(m){inti,j;for(i=0;i{for(j=0;j{printf("#");}printf("\n");}}23.若ax2+bx+c=0有实根,则求之。#include#includeintmain(){floata,b,c,disc,x1,x2,p,q;scanf("a=%f,b=%f,c=%f",&a,&b,&c);disc=b*b-4*a*c;if(disc<0){printf("meiyoushigen");}else{p=-b/(2*a);q=sqrt(disc)/(2*a);x1=p+q;x2=p-q;printf("\nx1=%5.2f\nx2=%5.2f\n",x1,x2);}return0;}24.从键盘输入两个字串,判断它们是否相同。#
if((x%j)==0)
22.输出n行由“#”组成的矩形,每行“#”的个数为m个,其中n、m由终端(键盘)输入。
要求输出m个“#”功能由函数satr(m)函数实现。
voidsatr(intm);
intm,n;
printf("qingshurumndezhi:
scanf("%d",&m);
satr(m);
voidsatr(m)
inti,j;
for(i=0;i{for(j=0;j{printf("#");}printf("\n");}}23.若ax2+bx+c=0有实根,则求之。#include#includeintmain(){floata,b,c,disc,x1,x2,p,q;scanf("a=%f,b=%f,c=%f",&a,&b,&c);disc=b*b-4*a*c;if(disc<0){printf("meiyoushigen");}else{p=-b/(2*a);q=sqrt(disc)/(2*a);x1=p+q;x2=p-q;printf("\nx1=%5.2f\nx2=%5.2f\n",x1,x2);}return0;}24.从键盘输入两个字串,判断它们是否相同。#
for(j=0;j{printf("#");}printf("\n");}}23.若ax2+bx+c=0有实根,则求之。#include#includeintmain(){floata,b,c,disc,x1,x2,p,q;scanf("a=%f,b=%f,c=%f",&a,&b,&c);disc=b*b-4*a*c;if(disc<0){printf("meiyoushigen");}else{p=-b/(2*a);q=sqrt(disc)/(2*a);x1=p+q;x2=p-q;printf("\nx1=%5.2f\nx2=%5.2f\n",x1,x2);}return0;}24.从键盘输入两个字串,判断它们是否相同。#
printf("#");
23.若ax2+bx+c=0有实根,则求之。
floata,b,c,disc,x1,x2,p,q;
scanf("a=%f,b=%f,c=%f",&a,&b,&c);
disc=b*b-4*a*c;
if(disc<0)
printf("meiyoushigen");
p=-b/(2*a);
q=sqrt(disc)/(2*a);
x1=p+q;x2=p-q;
printf("\nx1=%5.2f\nx2=%5.2f\n",x1,x2);
24.从键盘输入两个字串,判断它们是否相同。
#
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1