版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、2.2 #includemain()float x=2.5,y=2.5,z=2.5;printf(x=%fn,x);printf(y=%fn,y);printf(z=%fn,z);3.1(1) #includemain()int a=12,b=3;float x=18.5,y=4.6;printf(%dn,(float)(a*b)/2);printf(%dn,(int)x%(int)y);3.2 #includemain()int x,b0,b1,b2,s;printf(Inputx:);scanf(%d,&x);b2=x/100;b1=(x-b2*100)/10;b0=x%10;s=b0*1
2、00+b1*10+b2;printf(s=%dn,s);3.3 #include#includemain()float rate=0.0225;float n,capital,deposit;printf(Input n,capital:);scanf(%f,%f,&n,&capital);deposit=capital*pow(1+rate,n);printf(deposit=%fn,deposit);3.4 #include#includemain()float a,b,c;double x,y;printf(Inputa,b,c:);scanf(%f,%f,%f,&a,&b,&c);x=
3、(-b+sqrt(b*b-4*a*c)/(2*a);y=(-b-sqrt(b*b-4*a*c)/(2*a);printf(x=%f,y=%fn,x,y);4.1(1) #includemain()char c1=a,c2=b,c3=c;printf(a%cb%cc%cn,c1,c2,c3);4.1(2) #includemain()int a=12,b=15;printf(a=%d%,b=%d%n,a,b);4.1(3) #includemain()int a,b;scanf(%2d%*2s%2d,&a,&b);printf(%d,%dn,a,b);4.2 #includemain()long
4、 a,b;float x,y;scanf(%d,%dn,&a,&b);scanf(%f,%fn,&x,&y);printf(a=%d,b=%dn,a,b);printf(x=%f,b=%fn,x,y);5.1 #includemain()float a;printf(Innputa:);scanf(%f,&a);if(a=0)a=a;printf(a=%fn,a);elsea=-a;printf(a=%fn,a);5.2 #includemain()int a;printf(Inputa:);scanf(%d,&a);if(a%2=0)printf(a是偶數(shù));elseprintf(a是奇數(shù))
5、;5.3 #include#includemain()float a,b,c,s,area;printf(Inputa,b,c:);scanf(%f,%f,%f,&a,&b,&c);if(a+bc&a+cb&b+ca)s=(a+b+c)/2;area=(float)sqrt(s*(s-a)*(s-b)*(s-c);printf(area=%fn,area);elseprintf(不是三角形);5.4 #include#includemain()float a,b,c,x,y;printf(Inputa,b,c:);scanf(%f,%f,%f,&a,&b,&c);if(a=0)printf(該
6、方程不是一元二次方程n);if(b*b-4*a*c0)x=(-b+sqrt(b*b-4*a*c)/(2*a); y=(-b-sqrt(b*b-4*a*c)/(2*a);printf(x=%f,y=%fn,x,y);else if(b*b-4*a*c=0)x=-b/(2*a); y=-b/(2*a);printf(x=%f,y=%fn,x,y);elseprintf(該方程無實根n);5.5 #includemain()int year,flag;printf(Input a year:);scanf(%d,&year);if(year%4=0&year%400!=0|year%400=0)fl
7、ag=1;elseflag=0;if(flag=1)printf(%d is a leap year !n,year);elseprintf(%d is not a leap year !n,year);5.6 #includemain()int year,flag;printf(Input a year:);scanf(%d,&year);flag=year%400=0|year%4=0&year%100!=0?1:0;if(flag=1&flag!=0)printf(%d is a leap year !n,year); elseprintf(%d is not a leap year !
8、n,year);5.7 #includemain()char ch;printf(Inputch:);scanf(%c,&ch);if(ch=a&ch=A&ch=Z)ch=getchar();ch=ch+32;printf(%c,%dn,ch,ch);elseprintf(%c,ch);5.8 #includemain()char ch;printf(Inputch:);scanf(%c,&ch);if(ch=48&ch=65&ch=97&ch=122)printf(ch是小寫字母n); else if(ch=32)printf(ch是空格n);else printf(ch是其他字符n);5.
9、9 #includemain()int score,grade;printf(Input score:);scanf(%d,&score);grade=score/10;if(score100) printf(Input errorn); if(score=90&score=80&score=70&score=60&score=0&score60)printf(%d- -En,score);5.10 #includemain()int year,month;printf(Input year,month:);scanf(%d,%d,&year,&month); if(month12|month
10、=0)printf(error monthn); else switch(year,month)case 12:case 10:case 8:case 7:case 5:case 3:case 1:printf(31天n);break;case 11:case 9:case 6:case 4:printf(30天n); break;case 2:if(year%4=0&year!=0|year%400=0)printf(29天n);elseprintf(28天n); break; default: printf(Input errorn); 6.1(1) #includemain()int i
11、,j,k;char space= ;for(i=1;i=4;i+)for(j=1;j=i;j+)printf(%c,space);for(k=1;k=6;k+)printf(*);printf(n);6.1(2) #includemain()int k=4,n;for(n=0;nk;n+)if(n%2=0) continue;k-;printf(k=%dn,n=%dn,k,n);6.1(3) #includemain()int k=4,n;for(n=0;nk;n+)if(n%2=0) break;k-;printf(k=%d,n=%dn,k,n);6.2(1) #includemain()i
12、nt i,sum=0;for(i=1;i=101;i+)sum=sum+i;printf(sum=%dn,sum);6.2(2) #includemain()long i;long term,sum=0;for(i=1;i=101;i=i+2)term=i*(i+1)*(i+2);sum=sum+term;printf(sum=%ldn,sum);6.2(4) #include#includemain()int n=1;float term=1.0,sign=1,sum=0;while(term=1e-4)term=1.0/sign;sum=sum+term;sign=sign+n;n+;pr
13、intf(sum=%fn,sum);6.2(5) #include#includemain()int n=1,count=1;float x;double sum,term;printf(Input x:);scanf(%f,&x);sum=x;term=x;doterm=-term*x*x/(n+1)*(n+2); sum=sum+term;n=n+2;count+;while(fabs(term)=1e-5);printf(sin(x)=%f,count=%dn,sum,count);6.3 #includemain()int x=1,find=0; while(!find)if(x%2=
14、1&x%3=2&x%5=4&x%6=5&x%7=0)printf(x=%dn,x);find=1;x+;/*int x,find=0;for (x=1;!find;x+)if(x%2=1&x%3=2&x%5=4&x%6=5&x%7=0)printf(x=%dn,x);find=1;*/6.4 #includemain()int i,n;long p=1,m=1;printf(Input n:);scanf(%d,&n);for(i=1;i=n;i+)p=i*i;m=i*i*i;printf(p=%d,m=%dn,i,p,i,m);6.5 #includemain()float c,f;for(
15、c=-40;c=110;c=c+10)f=9/5*c+32;printf(f=%fn,f);6.6 #include#includemain()int n;double c=0.01875,x;dox=x*pow(1+c,12)-1000;n+;while(x0);printf(x=%dn,x);6.7 #includemain()int n=0;float a=100.0,c;printf(Inputc:);scanf(%f,&c);doa=a*(1+c);n+;while(a=200);printf(n=%dn,n);6.8 #include#includemain()int n=1,co
16、unt=1;double sum=1,term=1;while(fabs(term)=1e-5)term=pow(-1,count)*(1.0/(n+2);sum=sum+term;n=n+2;count+; sum=4*sum;printf(sum=%f,count=%dn,sum,count);6.9 #include#includemain()int n=1,count=1;double sum=1,term=1;while(fabs(term)=1e-5)term=term*(1.0/n);sum=sum+term; n+;count+;printf(sum=%f,count=%dn,
17、sum,count);6.10 #include#includemain()int x;for(x=100;x=999;x+)if(x=pow(x/100,3)+pow(x/10%10,3)+pow(x%10,3)printf(x=%dn,x);6.11 #includemain()int i=0,n;long sum=0,term=1;printf(Inputn:);scanf(%d,&n);doi+;term=term*i;sum=sum+term;while(sumn);printf(%dn,i-1);6.12 #includemain()int i,n,m,count=0,sum=0;
18、printf(Input n:);scanf(%d,&n);for(i=1;i0)sum=sum+m;count+;elsebreak;printf(sum=%d,count=%dn,sum,count);6.13 #includemain()int i,n,m,count=0,sum=0;printf(Inputn:);scanf(%d,&n);for(i=1;i0|m0)sum=sum+m;count+;elsebreak;printf(sum=%d,count=%dn,sum,count);6.14 #includemain()int x,y,z;for(x=0;x=17;x+)for(
19、y=0;y=25;y+)3*x+2*y+z=50;z=30-x-y;if(3*x+2*y+z=50&x+y+z=30)printf(x=%d,y=%d,z=%dn,x,y,z);6.15 #includemain()int x,y;for(x=0;x=98;x+)y=98-x;2*x+4*y=386;if(x+y=98&2*x+4*y=386)printf(x=%d,y=%dn,x,y);6.16 #includemain()int x,y,z;for(x=0;x=20;x+)for(y=0;y=33;y+) 3*y+5*x+z/3.0=100; z=100-x-y; if (5*x+3*y+
20、z/3.0=100&z+x+y=100) printf(x=%d,y=%d,z=%dn,x,y,z); 6.17 #includemain()int x,y,z;for(x=1;x=9;x+)for(y=1;y0) printf(x=%d,y=%d,z=%dn,x,y,z);7.1 #includeint Square(int i)return i*i;int main()int i=0;i=Square(i);for( ;i3;i+)static int i=1;i+=Square(i);printf(%d,i);printf(%dn,i);return 0;7.2 #includeint
21、hour,minute,second;void update()second+;if(second=60)second=0;minute+;if(minute=60)minute=0;hour+;if(hour=24)hour=0;void display()printf(%d,%d,%dn,hour,minute,second);void delay()int t;for(t=0;t100000000;t+);int main()int i;void updaye(),display(),delay();for(i=0;i1000000;i+)update();display();delay
22、();return 0;7.3 #includeint GetMax(int a,int b);int main()int x,y,max;printf(Inputx,y:);scanf(%d,%d,&x,&y);max=GetMax(x,y);printf(max=%dn,max);return 0;int GetMax(int m,int n)if(m=n)return m;else return n;7.4 #includeint LCM(int n,int m);int main()int a,b;printf(Inputa,b:);scanf(%d,%d,&a,&b);printf(
23、%dn,LCM(a,b);return 0;int LCM(int n,int m)int x;int find=0;for(x=1;!find;x+)if(x%n=0&x%m=0) find=1;return x-1;7.5 #includelong Fact(int n);int main()int m,a;printf(Inputm:);scanf(%d,&m);for(a=1;a=m;a+) printf(%d!=%ldn,a,Fact(a);return 0;long Fact(int n)int i;long result=1;for(i=2;i=n;i+)result*=i;re
24、turn result;7.6 #includelong Fact(int n);int main()int m;long ret;printf(Inputm:);scanf(%d,&m);ret=Fact(m);printf(ret=%dn,ret);return 0;long Fact(int n)int i;long result=1,sum=0;for(i=2;i=n;i+)result*=i;sum=sum+result;return sum;7.7(1) #includeint Gcd(int a,int b);int main()int m,n;printf(Inputm,n:)
25、;scanf(%d,%d,&m,&n);printf(%dn,Gcd(m,n);return 0;int Gcd(int a,int b)int t,min,find=0;min=ab?a:b;t=min;for(t=min;!find;t-)a%t=0; b%t=0;if(a%t=0&b%t=0)return t;find=1;7.7(2) #includeint Gcd(int a,int b);int main()int m,n;printf(Inputm,n:);scanf(%d,%d,&m,&n);printf(%dn,Gcd(m,n);return 0;int Gcd(int a,
26、int b)int r,temp;r=a%b;if(r=0)return b;elsedotemp=b; b=r;a=temp;r=a%b;while(r!=0);return b;8.1(1) #includevoid Func(int x)x=2;int main()int x=10;Func(x);printf(%d,x);return 0;8.1(2) #includevoid Func(int b)int j;for(j=0;j4;j+)bj=j;int main()static int a=5,6,7,8,i;Func(a);for(i=0;i4;i+)printf(%d,ai);
27、return 0;8.2(1) int PositiveNum(int a,int n)int i,count=0;for(i=0;i0)count+;return 0;8.2(2) void Fib(long f,long n)int i;f0=0;f1=1;for(i=2;in;i+)fi=fi-1+fi-2;8.2(3) #includeint main()int a10,n,max,min,maxPos,minPos;for(n=0;n10;n+)scanf(%d,&an);max=min=a0;maxPos=minPos=0;for(n=0;nmax)max=an;maxPos=n;
28、else if(anmin)min=an;minPos=n;printf(max=%d,pos=%dn,max,maxPos);printf(min=%d,pos=%dn,min,minPos);return 0;8.3 void DivArray(int *pArray,int n)int i;for(i=0;in;i+)pArrayi/=pAttay0;8.4 #include#define N 40int FailNum(int score,int n);void ReadScore(int score,int n);int main()int scoreN,n;printf(Input
29、 n:);scanf(%d,&n);ReadScore(score,n);FailNum(score,n);printf(FailNum students are %dn,FailNum(score,n);return 0;int FailNum(int score,int n)int i,count=0;for(i=0;in;i+)if(scorei60)count+;return count;void ReadScore(int score,int n)int i;printf(Input score:);for(i=0;in;i+)scanf(%d,&scorei);8.5 #inclu
30、de#define N 40int HighAver(int score,int n);int ReadScore(int score);int main()int scoreN,n;n=ReadScore(score);printf(HighAver students are %dn,HighAver(score,n);return 0;int HighAver(int score,int n)int i,count=0,sum=0,aver;for(i=0;in;i+)sum=sum+scorei;aver=sum/n;for(i=0;iaver)count+;return count;i
31、nt ReadScore(int score)int i=-1;doi+;printf(Input score:);scanf(%d,&scorei);while(scorei=0);return i;8.6 #include#define N 40int ReadScore(int score,long num);int FindMax(int score,long num,int n);int main()int scoreN,n,max,num,t;long numN;t=FindMax(score,n);max=scoret;num=numt;printf(max=%d,num=%dn
32、,max,num);return 0;int ReadScore(int score,long num)int i=-1;doi+;printf(Input students ID and score:);scanf(%ld%d,&numi,&scorei);while(numi0&scorei=0);return i;int FindMax(int score,long num,int n)int max,i;max=score0;for(i=1;imax)max=scorei;return i;8.7 #include#define N 40int Read(int a);int Chan
33、geArry(int a,int n);int main()int aN,n;printf(%dn,ChangeArry(a,n);return 0;int Read(int a)int i;for(i=0;i9;i+)printf(Input a:);scanf(%d,&ai);return i;int ChangeArry(int a,int n)int max,min,i,maxpos,minpos,term;max=min=score0;for(i=1;imax)max=scorei;maxpos=n;else(aimin)min=ai;minpos=n;temp=maxpos;max
34、pos=minpos;minpos=temp;return ai;8.10 #include#define N 5void main()int aNN;int sum = 0;int i, j; printf(請輸入一個%d*%d的矩陣n,N,N);for(i = 0; i N; i+)for(j = 0; j N; j+)scanf(%d,&aij);for(i = 0; i N; i+)for(j = 0; j N; j+)if(i = j | i + j = N - 1)sum=sum+aij;printf(對角線元素之和為:%dn,sum);8.11 #include#define N
35、 2#define M 3void main()int aNM,bNM;int i,j,sum1=0,sum2=0,sum=0;printf(請輸入一個%d*%d的矩陣n,N,M);for(i = 0; iN; i+)for(j = 0; j M; j+)scanf(%d,&aij);sum1=sum1+aij;printf(請輸入一個%d*%d的矩陣n,N,M);for(i = 0; i N; i+)for(j = 0; j M; j+)scanf(%d,&bij);sum2=sum2+aij;sum=sum1+sum2;printf(sum=%dn,sum);8.12 #include#d
36、efine N 7void YangHui(int aNN,int n);void main()int i,j,n,bNN;printf(Input n:);scanf(%d,&n);YangHui(b,n);for(i=0;in;i+)for(j=0;j=i;j+)printf(%4d,bij);printf(n);void YangHui(int aNN,int n)int i,j;for(i=0;in;i+)ai0=1;aii=1;for(i=2;in;i+)for(j=1;ji;j+)aij=ai-1j-1+ai-1j;8.13 #include#define N 12void mai
37、n()int i;int fN=1,1;printf(%d:%dn,0,f0);printf(%d:%dn,1,f1);for(i=2;iN;i+)fi=fi-1+fi-2;printf(%d:%dn,i+1,fi);8.14 #include#include#include#define N 6000void main()int aN,i;int b1=0,b2=0,b3=0,b4=0,b5=0,b6=0;float p1,p2,p3,p4,p5,p6;srand(time(NULL);for(i=0;iN;i+)ai=rand()%6+1;printf(%3d,ai);if(ai=1)b1
38、+;if(ai=2) b2+;if(ai=3)b3+;if(ai=4)b4+;if(ai=5)b5+;if(ai=6)b6+;p1=(float)(b1/6000.0);p2=(float)(b2/6000.0);p3=(float)(b3/6000.0);p4=(float)(b4/6000.0);p5=(float)(b5/6000.0);p6=(float)(b6/6000.0);printf(骰子出現(xiàn)1的概率:%.2fn,p1);printf(骰子出現(xiàn)2的概率:%.2fn,p2);printf(骰子出現(xiàn)3的概率:%.2fn,p3);printf(骰子出現(xiàn)4的概率:%.2fn,p4);printf(骰子出現(xiàn)5的概率:%.2fn,p5);printf(骰子出現(xiàn)6的概率:%.2fn,p6);9.1(1) void Swap(int *x,int *y)int *pTemp;/*pTemp未進行初始化,*pTemp指向哪里位置*pTemp=*x;*x=*y;*y=*pTemp;9.1(2) void Swap(int *x,int *y)int *pTemp;pTemp=x;x=y;y=pTemp;/錯誤,x,y沒有指向類型9.2 #inc
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 福建師范大學(xué)《管理學(xué)概論》2021-2022學(xué)年第一學(xué)期期末試卷
- 福建師范大學(xué)《地圖學(xué)實驗》2021-2022學(xué)年第一學(xué)期期末試卷
- 四川省成都市2020年中考英語真題(含答案)
- 2024秋國家開放大學(xué)《思想道德與法制》專題測驗1-7答案
- 油田制度流程類 油田動火作業(yè)安全管理實施細則(陸上石油天然氣開采)
- 班級常規(guī)調(diào)研活動分析
- 檔案行政執(zhí)法人員統(tǒng)計表
- 感恩教育課件教學(xué)課件
- 2024年四川客運從業(yè)資格證實操考試需要準(zhǔn)備什么
- 2024年合肥客車駕駛員考試試題
- 新《固廢法》解讀(專業(yè)版)
- 領(lǐng)導(dǎo)及上下級關(guān)系處理講義
- Catia百格線生成宏
- 業(yè)務(wù)流程繪制方法IDEF和IDEFPPT課件
- 鍋爐安全基礎(chǔ)知識
- 幼兒園科學(xué)教育論文范文
- 駕校質(zhì)量信譽考核制度
- 用電檢查工作流程圖
- 電動葫蘆的設(shè)計計算電動起重機械畢業(yè)設(shè)計論文
- (完整版)學(xué)校安辦主任安全工作職責(zé)
- PCR儀使用手冊
評論
0/150
提交評論