c++基础例题100道.doc
《c++基础例题100道.doc》由会员分享,可在线阅读,更多相关《c++基础例题100道.doc(49页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、/* 1153153 = 13 + 53 + 33 */#includevoid main()int i, a=0, b=0, c=0;for(i=100;i1000;i+)a=i%10;b=i/10%10;c=i/100%10;if(a*a*a+b*b*b+c*c*c=i)couti=iendl;/* 261236 = 1 + 2 + 3610006 -123 */#includevoid main()int i,j,sum=0,a50,k,t;for(i=1;i=1000;i+)sum=0;for(j=1;ji;j+)if(i%j=0)sum+=j;ak+=j;t=k;if(sum=i)c
2、outi;for(k=0;kt;k+)coutak;if(kt-1)cout,;coutendl;k=0;/* 3Sn=a+aa+aaa+aaaa2+22+222+22222n=5n*/#includevoid main()double a,sn=0.0,sum=0.0;int n,i;couta;coutn;sn=a;sum=a;for(i=2;i=n;i+)sum=sum*10+a;sn+=sum;coutSn=snendl;/* 41001010*/#includevoid main()double h1=100,h2=100,sum=0.0;int i;for(i=1;i=10;i+)
3、sum+=h2;h1=h1/2.0;h2=h1*2;coutsum=sum h1=h1endl;/* 510*/#includevoid main()int number,i;number=1;for(i=10;i1;i-)number=(number+1)*2;coutnumber=numberendl;4 /* 110*/#includevoid main()int i,j,temp,a10;coutplease input ten numbers:n;for(i=0;iai;for(i=0;i10;i+) /for(j=i+1;jaj)temp=aj;aj=ai;ai=temp;cout
4、resort result=;for(i=0;i10;i+)coutai 1) */#includedouble fun (double,double);void main()double n,x,sum;coutinput n and xnx;sum=fun(n,x);coutPn(x)=sum1)return (2*n1-1)*x1*fun(n1-1,x1)-(n1-1)*fun(n1-2,x1)/n1;/* 3 */#includevoid judge(char a);void main()const int size=100;char asize;cin.getline(a,size)
5、;judge(a);void judge(char a100)/int letter=0,number=0,others=0,i=0;while(ai!=0)if (ai=a&ai=A&ai=0 & ai=9) number+;/else others+;/i+;coutletter=letter number=number others=othersendl;/* 4 */#includeint lead(int);void main()int ly,year,month,date,i,sum=0;coutyearmonthdate;int a12=31,0,31,30,31,30,31,3
6、1,30,31,30,31;ly=lead(year);if (ly=1)a1=29;/366else a1=28;/365for(i=0;imonth-1;i+) /sum+=ai;sum+=date; /coutsum;int lead(int y)/if(y%4=0&y%100!=0)|(y%400=0) return 1;/else return 0;/* 5 */#includeint cdivisor(int,int);int cmultiple(int,int,int);void main()int x,y,d,m;coutxy;d=cdivisor(x,y);m=cmultip
7、le(x,y,d);coutcommon divisor is dendlcommon multiple is mendl;int cdivisor(int x1,int y1)/int r,temp;if (x1y1)temp=x1;x1=y1;y1=temp;while(x1%y1)/0r=x1%y1;x1=y1;y1=r;return y1;int cmultiple(int x2,int y2,int d1)/return x2*y2/d1;/* 6 */#include#includevoid main()const int size=100;char asize,bsize;cou
8、tinput two string:endl;cin.getline(a,size);cin.getline(b,size);strcat(a,b);couta=aendl;/* 7 */#include#includevoid scpy(char *,char *);void main()const int size=100;char asize=Hello world;char bsize=Net;couta= ab= bendl;scpy(a,b);couta= aendl;void scpy(char *p,char *q)while(*q!=0)if (*q=a|*q=A|*q=e|
9、*q=E|*q=i|*q=I|*q=o|*q=O|*q=u|*q=U)* p+=*q;q+;/* 8419901 9 9 0 */#include#includevoid outs(char a);void main()const int size=10;char asize;cin.getline(a,size);outs(a);void outs(char a10)int i;if(strlen(a)=4)for(i=0;i4;i+)coutai ;else coutinput error.endl;5 /* 1abcddcba */#includevoid back(char *);vo
10、id main()char a50=abcdefg;couta=aendl;back(a);#includevoid back(char *p)int i=0;while(*p!=0)p+;/i+;/cout0;i-)/p-;cout*p;coutendl;/* 215(1) */#includevoid tri(int a15);void main()int i,j,a1515;tri (a);couta= ;for(i=0;i15;i+)/for(j=0;j=i;j+)cout=1&aij=9)/4cout=10&aij=99)/3cout=100&aij=999)/2cout ;else
11、 cout ;/1coutendl ;/void tri(int a1515)int i,j;for(i=0;i15;i+)for(j=0;j=i;j+)if(j=0|j=i)/1aij=1;else aij=ai-1j-1+ai-1j;/* 3strcat */#include#includevoid scat(char *,char *);void main()const int size=100;char asize=Hello;char bsize=Bye;couta=a b=bendl;scat(a,b);couta=a after link a and bendl;void sca
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- c+ 基础 例题 100
限制150内