您好,欢迎访问三七文档
当前位置:首页 > 临时分类 > 同济大学 C++ 程序设计实验篇
C/C++1C/C++23456789101.#includeiostreamusingnamespacestd;intmain(){intx;cinx;inty=x*x;coutx^2=yendl;system(pause);return0;}2.#includeiostreamusingnamespacestd;intmain(){doublea,b,h;C/C++1C/C++cout;cinabh;cout=(a+b)*h/2endl;system(pause);return0;}3.#includeiostreamusingnamespacestd;intmain(){inta,b,c;cout;cinabc;cout(a+b+c)/3endl;system(pause);return0;}4.#includeiostream#definea5.52usingnamespacestd;intmain(){doubler;coutendl;cinr;r=r*1000;cout4*3.14*r*r*r*a/3endl;system(pause);return0;}1.#includeiostream2usingnamespacestd;intmain(){floats1,s2,s3;doubleaver;coutendl;cins1s2s3;aver=(s1+s2+s3)/3;aver=aver*100+0.5;aver=(int)aver;aver=aver/100;coutaverendl;system(pause);return0;}2.#includecmath#includeiostreamusingnamespacestd;intmain(){doublea,b,c;cout;cinab;c=sqrt(a*a+b*b);coutcendl;system(pause);return0;}3.#includeiostreamusingnamespacestd;intmain(){doublex,y;coutxy;cinxy;cout(x*x+y*y=4&&x*x+y*y=16?3.14*(4*4-2*2):0)endl;system(pause);return0;}4.#includeiostreamusingnamespacestd;intmain(){doublea,b,c,max;cout3;cinabc;max=ab?a:b;max=maxc?max:c;cout=(a+b+c)/3=maxendl;system(pause);return0;}5.#includeiostreamusingnamespacestd;intmain(){charc1,c2,c3;c1='f';c2='l';c3='y';c1=c1+3;c2=c2+3;c3=c3-23;coutc1c2c3endl;system(pause);return0;}1.3#includeiostreamusingnamespacestd;intmain(){intx,y,r1,r2;cinxy;if(x==0||y==0)coutendl;else{r1=x/y;r2=x%y;cout=r1=r2endl;}system(pause);return0;}2.#includeiostreamusingnamespacestd;intmain(){doublex,y;coutendl;cinx;if(x10)y=30;elseif(x=10&&x50)y=2.5*x;elsey=2*x;coutyendl;system(pause);return0;}3.#includeiostreamusingnamespacestd;intmain(){intx,a;cinx;if(x1000)a=1;elseif(x=1000&&x2000)a=2;elseif(x=2000&&x3000)a=3;elsea=4;switch(a){case1:coutxendl;break;case2:cout0.9*xendl;break;case3:cout0.8*xendl;break;default:cout0.7*xendl;break;}system(pause);return0;}4.#includeiostreamusingnamespacestd;intmain(){doublex,y,z,a;coutendl;cinxyz;if(xy){a=x;x=y;y=a;}if(yz){a=y;y=z;z=a;}if(xy){a=x;x=y;y=a;}coutxyzendl;system(pause);return0;}5.#includeiostreamusingnamespacestd;intmain(){doublea,b;charx;cout12endl;cinaxb;switch(x){case'+':couta+b=a+bendl;break;case'-':couta-b=a-bendl;break;case'*':coutaxb=a*bendl;break;case'/':couta/b=a/bendl;break;}system(pause);return0;}6.#includecmath#includeiostreamusingnamespacestd;intmain(){doublea,b,c,d;coutendl;cinabc;d=b*b-4*a*c;if(d0)coutendl;elsecoutx1=(-b+sqrt(d)/(2*a))x2=(-b-sqrt(d))/(2*a)endl;system(pause);return0;}1.#includecmath#includeiostreamusingnamespacestd;intmain(){doublea,b,c,d;coutendl;cinabc;d=b*b-4*a*c;if(d0)coutendl;elsecoutx1=(-b+sqrt(d)/(2*a))x2=(-b-sqrt(d))/(2*a)endl;system(pause);return0;}2.#includeiostreamusingnamespacestd;intmain(){inta,b,c;cout;cina;for(b=1,c=1;b!=0;a=b){4b=a/10;c=a%10;coutc;}system(pause);return0;}3.#includeiostreamusingnamespacestd;intmain(){doublet=2,i=2,sum=1;while(t=10000){sum=sum+1/t;t=t+i;i=i+1;}coutS=sumendl;system(pause);return0;}4.#includeiostreamusingnamespacestd;intmain(){intn;doubles=2;for(n=1;n=10000;n=n+1){s=(s*4*n*n)/((2*n-1)*(2*n+1));switch(n){case10:coutn=10π≈sendl;break;case100:coutn=100π≈sendl;break;case1000:coutn=1000π≈sendl;break;default:;}}coutπ≈sendl;system(pause);return0;}5.#includeiomanip#includeiostreamusingnamespacestd;intpractice1(){inti,j;for(i=9;i0;i--){coutsetw(i);for(j=0;j(9-i)*2+1;j++)cout10-i;coutendl;}return0;}intpractice2(){inti,j;charc;for(i=0;i9;i++){coutsetw(i+1);for(j=(9-i)*2;j0;j--){c=i+'A';coutc;}coutendl;}return0;}intmain(){cout(1).endl;practice1();coutendl(2).endl;practice2();system(pause);return0;}6.#includeiostreamusingnamespacestd;intmain(){inta,b,c;for(a=1;a10;a++){for(b=0;b10;b++){for(c=0;c10;c++){if(100*a+10*b+c==a*a*a+b*b*b+c*c*c)coutabcendl;}}}system(pause);return0;}7.#includeiomanip#includeiostreamusingnamespacestd;intmain(){intx,y,z,i=0;for(x=1;x5;x++){for(y=2;y6;y++){for(z=5;z7;z++){if(xy&&yz){i++;coutxsetw(8)ysetw(8)zendl;}}}}coutiendl;system(pause);return0;}8.#includecstdlib#includeiostreamusingnamespacestd;intmain(){inta,i,n;doubletemp=0,sum=0;a=rand()%9+1;n=rand()%6+5;for(i=1;i=n;i++){temp=temp*10+a;sum=sum+temp;}coutsum;system(pause);return0;}9.#includecmath#includeiomanip#includeiostreamusingnamespacestd;intmain(){doublea,x0,x1;for(a=1;a=30;a++){x1=a;do{x0=x1;x1=2*x0/3+a/(3*x0*x0);}while(fabs(x1-x0)=1.0e-5);if(a==1||a==3||a==27)coutx1setw(10)pow(a,1.0/3)endl;}system(pause);return0;}1.#includecstdlib#includeiostreamusingnamespacestd;5intmain(){inti,j,t,a[10],sum=0,min,max;doubleaver;for(i=0;i10;i++){a[i]=rand()%71+30;couta[i];sum=sum+a[i];}for(i=0;i10;i++){for(j=i+1;
本文标题:同济大学 C++ 程序设计实验篇
链接地址:https://www.777doc.com/doc-4339455 .html