資源描述:
《c語(yǔ)言復(fù)習(xí)(4)》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在學(xué)術(shù)論文-天天文庫(kù)。
1、1、求1+2+3+……….+100。(循環(huán))答案#includevoidmain(){inti,sum=0;for(i=1;i<=100;i++)sum=sum+i;printf("%d",sum);}2、求1*2*3*……….*10。(循環(huán))答案voidmain(){inti=0,j=1;for(i=2;i<=10;i++){j*=i;}printf("%d",j);return0;}3、輸入三個(gè)數(shù)字,輸出他們的最大值。(if)答案#includevoidmain(){inta,b,c,d;scanf("%d,%d,%d",
2、&a,&b,&c);d=max(a,b,c);printf("max=%d",d);getch();/*暫??催\(yùn)行結(jié)果*/}intmax(intx,inty,intz){intu;if(x>=y&&x>=z)u=x;elseif(y>=x&&y>=z)u=y;elseu=z;return(u);4.用起泡法對(duì)十個(gè)數(shù)據(jù)排序(數(shù)組實(shí)現(xiàn))答案#includemain(){inti,j,t;staticinta[10]={5,7,4,2,3,6,1,0,9,8};for(j=0;j<9;j++){for(i=0;i<9-j;i++){if(a[i]>a
3、[i+1]){t=a[i];a[i]=a[i+1];a[i+1]=t;}}}for(i=0;i<10;i++)printf("%2d",a[i]);}5、輸入十個(gè)數(shù)字,逆序輸出。(數(shù)組實(shí)現(xiàn))答案#includemain(){inta[10],i=0;for(i=0;i<=9;i++)scanf("%f",&a[i]);printf("");for(i=9;i>=0;i--)printf("%f",a[i]);}6輸入兩個(gè)數(shù),交換他們的值并輸出。(元素交換)答案#includeintmain(){intm,n,temp;sc
4、anf("%d%d",&m,&n);if(mvoidmain(){inti=1;for(i;i<=9;i++){intj=1;for(j;j<=i;j++){printf("%d*%d=%d",i,j,i*j);}printf("");}}8.輸入一行字符,將所有的小寫(xiě)字母轉(zhuǎn)換成大寫(xiě)字母,大寫(xiě)字母轉(zhuǎn)換成小寫(xiě)字母,其余字符不變。輸出轉(zhuǎn)變后的這行字符。答案#include"stdio.h"voidm
5、ain(){chara[n];inti;scanf("%s",a);printf("大寫(xiě)為:");for(i=0;i<=n;i++){if(a[i]<='z'&&a[i]>='a')a[i]=a[i]-32;printf("%c",a[i]);}printf("小寫(xiě)為:");for(i=0;i<=3;i++){a[i]=a[i]+32;printf("%c",a[i]);}}9、編寫(xiě)一個(gè)簡(jiǎn)單計(jì)算器程序,要求能夠完成兩個(gè)數(shù)的+,-,*,/四種運(yùn)算。輸出運(yùn)算式及運(yùn)算結(jié)果。(switch)6.2#include"stdio.h"main(){charc;inti=
6、0,j=0,k=0,l=0;while((c=getchar())!=’’){if(c>=65&&c<=90
7、
8、c>=97&&c<=122)i++;elseif(c>=48&&c<=57)j++;elseif(c==32)k++;elsel++;}printf("i=%d,j=%d,k=%d,l=%d",i,j,k,l);}6.6#include"math.h"main(){intx=100,a,b,c;while(x>=100&&x<1000){a=0.01*x;b=10*(0.01*x-a);c=x-100*a-10*b;if(x==(pow(a,3
9、)+pow(b,3)+pow(c,3)))printf("%5d",x);x++;}}6.7main(){intm,i,j,s;for(m=6;m<10000;m++){s=1;for(i=2;i10、%i==0)s=s-i;