資源描述:
《c語言基礎編程練習》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、1.屏幕上輸入:ThisisaCprogram#includeintmain(){printf("ThisisaCprogram.");return0;}2、求兩個整數(shù)之和#includevoidmain(){inta,b,sum;a=123;b=456;sum=a+b;printf("%d",sum);}3、求兩個整數(shù)中的較大者#includevoidmain(){intmax(intx,inty);inta,b,c;scanf("%d,%d",&a,&b);c=max(a,b);pri
2、ntf("max=%d",c);}intmax(intx,inty){intz;if(x>y)z=x;elsez=y;return(z);}4、編寫一個程序,輸入a,b,c三個值,輸出其中最大者#includevoidmain(){inta,b,c,max;printf("inputa,b,c:");scanf("%d,%d,%d",&a,&b,&c);max=a;if(maxvoidmai
3、n(){intt=1,i=2;while(i<=5){t=t*i;i=i+1;}printf("%d",t);}6、求多項式1-1/2+1/3-1/4+````+1/99-1/100的值#includevoidmain(){intsign=1;doubledeno=2.0,sum=1.0,term;while(deno<=100){sign=-sign;term=sign/deno;sum=sum+term;deno=deno+1;}printf("%f",sum);}7、將華氏溫度64°F轉(zhuǎn)換為攝氏度#include4、dio.h>voidmain(){floatf,c;f=64.0;c=(5.0/9.0)*(f-32);printf("c=%f",c);}8、1000元存一年:(1)活期,年利率為r1;(2)一年期頂起,年利率r2;(3)存兩次半年定期,年利率為r3.分別計算3種方法本息和#includevoidmain(){floatp0=1000,r1=0.0036,r2=0.0225,r3=0.0193,p1,p2,p3;p1=p0*(1+r1);p2=p0*(1+r2);p3=p0*(1+r3/2)*(1+r3/2);printf("
5、p1=%fp2=%fp3=%f",p1,p2,p3);}9、給定一個大寫字母A,輸出其小寫字母#includevoidmain(){charc1,c2;c1='A';c2=c1+32;printf("%c",c2);printf("%d",c2);}10、給出三角形三邊長,求面積#include#includeintmain(){doublea,b,c,s,area;a=3.67;b=5.43;c=6.21;s=(a+b+c)/2;area=sqrt(s*(s-a)*(s-b)*
6、(s-c));printf("a=%ftb=%ftc=%f",a,b,c);printf("area=%f",area);}11、輸入一個double類型的數(shù),使該數(shù)保留小數(shù)點后兩位,對第三位小數(shù)進行四舍五入后處理,然后輸出此數(shù),以便驗證處理是否正確。#includevoidmain(){doublex;printf("Enterx:");scanf("%lf",&x);printf("(1)x=%f",x);x=x*100+0.5;x=(int)x;x=x/100;printf("(2)x=%f",x);}12
7、、編程從鍵盤輸入兩個整數(shù)給變量x和y,然后輸出x和y的值,最后交換x和y的值并輸出。#includevoidmain(){intx,y,t;printf("Enterx,y:");scanf("%d%d",&x,&y);printf("x=%dy=%d",x,y);t=x;x=y;y=t;printf("x=%dy=%d",x,y);}13、從鍵盤輸入兩個兩位的正整數(shù)給變量x和y,并將x和y合并形成一個整數(shù)放在變量z中。合并的方式是:將數(shù)x的十位和各位依次放在z的千位和十位,將y的十位和個位放在z的個位和百位上。#inc
8、ludevoidmain(){intx,y,z;printf("Inputx,y:");s