资源描述:
《[法律资料]113道c语言题目》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、113道C语言题目,超经典的1.输入两个正整数,m和n,求其最大公约数和最小公倍数。#includevoidmain(){inthcf(int,int);/*函数声明*/intlcd(int,int,int);/*函数声明*/intu,v,h,l;printf("Pleaseinputtwonumbers:");scanf("%d,%d",&u,&v);h=hcf(u,v);printf("H.C.F=%d",h);l=lcd(u,v,h);printf("L.C.D=%d",l);}inthcf(intu,intv){intt,r
2、;if(v>u){t=u;u=v;v=t;}while((r=u%v)!=0){u=v;v=r;}return(v);}intlcd(intu,intv,inth){return(u*v/h);}2.输入一行字符,分别统计出其中字母、空格、数字和其他字符的个数。#includeintletter,digit,space,others;voidmain(){voidcount(char[]);chartext[80];printf("Pleaseinputstring:");gets(text);printf("string:");put
3、s(text);letter=0;digit=0;space=0;others=0;count(text);printf("letter:%d,digit:%d,space:%d,others:%d",letter,digit,space,others);}voidcount(charstr[]){inti;for(i=0;str[i]!=' ';i++)if((str[i]>='a'&&str[i]<='z')
4、
5、(str[i]>='A'&&str[i]<='Z'))letter++;elseif(str[i]>='0'&&str[i]<='9')dig
6、it++;elseif(str[i]==32)space++;elseothers++;}3.输入一个正整数求出它是几位数;输出原数和位数。#includeintdigit;voidmain(){voidcount(char[]);chartext[80];printf("Pleaseinputnumbers:");gets(text);printf("Numbers:");puts(text);digit=0;count(text);printf("digit:%d",digit);}voidcount(charstr[]){in
7、ti;for(i=0;str[i]!=' ';i++)if(str[i]>='0'&&str[i]<='9')digit++;}4.输入一个正整数,输出原数并逆序打印出各位数字。#includevoidinvertLongInt(long);voidmain(){unsignedlongiNumber;printf("Pleaseinputanumber:");scanf("%ld",&iNumber);printf("Theinputnumberis:%ld",iNumber);printf("Theinversenumberis:
8、");invertLongInt(iNumber);}voidinvertLongInt(longx){if(x>=0&&x<=9)printf("%d",x);else{printf("%d",x%10);invertLongInt(x/10);}}5.从键盘上输入若干学生的一门课成绩,统计并输出最高成绩和最低成绩及相应的序号,当输入负数时结束输入。6.从键盘上输入若干学生的一门课成绩,计算出平均分,当输入负数时结束输入。将结果输出。7.求1!+2!+3!+……+20!,将结果输出。#includevoidmain(){floats=0,
9、t=1;intn;for(n=1;n<=20;n++){t=t*n;s=s+t;}printf("1!+2!+3!+……+20!=%e",s);}8.打印以下图案:****************#includevoidmain(){inti,j;printf("Thepictureis:");staticcharpicture[4][7]={{'','','','*'},{'','','*','*','*'},{'','*','*','*','*','*'},{'*','*','*','*','*','*','*'}};for(i=0
10、;i<=3;i++){f