资源描述:
《道C语言题目超经典的.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、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。if(v>u>{t
2、=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:">。puts(text
3、>。letter=0。digit=0。space=0。others=0。count(text>。54/54printf("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'>
6、digit++。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(charst
7、r[]>{inti。for(i=0。str[i]!=' '。i++>if(str[i]>='0'&&str[i]<='9'>digit++。}b5E2RGbCAP4.输入一个正整数,输出原数并逆序打印出各位数字。#includevoidinvertLongInt(long>。voidmain(>{unsignedlongiNumber。printf("Pleaseinputanumber:">。54/54scanf("%ld",&iNumber>。printf("Theinputnumberis:%ld",iNumber>。p
8、rintf("Theinversenumberis:">。invertLongInt(iNumber>。}voidinvertLongInt(longx>{if(x>=0&&x<=9>printf("%d",x>。else{printf("%d",x%10>。invertLongInt(x/10>。}}p1EanqFDPw5.从键盘上输入若干学生的一门课成绩,统计并输出最高成绩和最低成绩及相应的序号,当输入负数时结束输入。DXDiTa9E3d6.从键盘上输入若干学生的一门课成绩,计算出平均分,当输入负数时结束输入。将结果输出。7.求1!+2!+3!+
9、……+20!,将结果输出。#includevoidmain(>{floats=0,t=1。intn。for(n=1。n<=20。n++>{t=t*n。s=s+t。}printf("1!+2!+3!+……+20!=%e",s>。}RTCrpUDGiT8.打印以下图案:****************#includevoidmain(>{inti,j。printf("Thepictureis:">。staticcharpicture[4][7]={{'','','','*'},54/54{'','','*','*'
10、,'*'},{'','*','*','*','*','*'},{'*','*',