版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
網(wǎng)站上機(jī)程序參考源代碼1:sizeof測(cè)試字節(jié)數(shù)#include<stdio.h>intmain(){printf("sizeof(char)=%d\n",sizeof(char));printf("sizeof(int)=%d\n",sizeof(int));printf("sizeof(short)=%d\n",sizeof(short));printf("sizeof(long)=%d\n",sizeof(long));printf("sizeof(unsignedint)=%d\n",sizeof(unsignedint));printf("sizeof(float)=%d\n",sizeof(float));printf("sizeof(double)=%d\n",sizeof(double));return0;}2:#include<stdio.h>intmain(){inta=20;floatb;doublec;b=12.345f;scanf("%lf",&c);printf("a=%d\n",a);printf("b=%f\n",b);printf("c=%f\n",c);return0;}3:用if語(yǔ)句求解分段函數(shù)#include<stdio.h>intmain(){doublex,y;scanf("%lf",&x);if(x<20)y=x+100;elseif(x<=100)elsey=x-100;printf("x=%f,y=%f\n",x,y);return0;}4#include<stdio.h>intmain(){intyear,month,day;scanf("%d%d",&year,&month);switch(month){case1:case3:case5:case7:case8:case10:case12:day=31;case4:case6:case9:case11:day=30;case2: day=28;if(year%4==0&&year%100!=0||year%400==0)day=29;break;default:printf("errormonth\n");}53位數(shù)字的質(zhì)數(shù)#include<stdio.h>#include<math.h>intmain(){intm,i,k,prime,count=0;for(m=101;m<999;m=m+2){k=(int)sqrt(m);prime=1;for(i=2;prime&&i<=k;i++)if(m%i==0)prime=0;if(prime){printf("%6d",m);count++;if(count%5==0)printf("\n");}}printf("\n");return0;}6#include<stdio.h>#include<math.h>intmain(){doublex,term=1,i=1,sum=0;intsign=1;scanf("%lf",&x);do{term=term*x/i;sum+=sign*term;sign=-sign;i++;}while(fabs(term)>=1e-5);printf("sum=%.2f\n",sum);return0;}7#include<stdio.h>intmain(){inti,a[20],max,min,sum=0,count=0;for(i=0;i<20;i++)scanf("%d",&a[i]);max=min=a[0];for(i=0;i<20;i++)if(a[i]>max)max=a[i];elseif(a[i]<min)min=a[i];for(i=0;i<20;i++)if(a[i]!=max&&a[i]!=min){sum+=a[i];count++;}printf("count=%d,average=%f\n",count,sum*1.0/count);return0;}8:用數(shù)組實(shí)現(xiàn)Fibonacci#include<stdio.h>intmain(){intn,f[40],i;do{scanf("%d",&n);}while(n<=0||n>40);f[0]=f[1]=1;for(i=2;i<n;i++)f[i]=f[i-2]+f[i-1];for(i=0;i<n;i++){printf("%12d",f[i]);if((i+1)%6==0)printf("\n");}printf("\n");return0;}9#include<stdio.h>intmain(){inta[20];inti=0,j,x,total=0,s=0;do{scanf("%d",&a[i++]);}while(a[i-1]);s=total=i;scanf("%d",&x);printf("Beforedelete,elementsare:\n");for(i=0;i<total;i++)printf("%5d",a[i]);printf("\n");for(i=0;i<total;i++){while(i<total&&a[i]!=x)if(i==total) break;for(j=i;j<total-1;j++)a[j]=a[j+1];i--;total--;}if(total==s)printf("doesnotexist,nooperating!\n");else{printf("Afterdelete,elementsare:\n");for(i=0;i<total;i++)printf("%5d",a[i]);printf("\n");}return0;}編程題10#include<stdio.h>#include<stdlib.h>voidcreate(inta[],intn);voidprint(inta[],intn); //intmain(){intn,*array;scanf("%d",&n); //讀入整數(shù)n,再調(diào)用calloc函數(shù)產(chǎn)生大小為n的數(shù)組array=(int*)calloc(n,sizeof(int));create(array,n); //調(diào)用create函數(shù)產(chǎn)生n個(gè)元print(array,n); //調(diào)用free(array);return0;}voidcreate(inta[],intn){inti;for(i=0;i<n;i++) //i控制將要產(chǎn)生的其它n-1個(gè)元素的下標(biāo){a[i]=i+1;}}voidprint(inta[],intn){inti;for(i=0;i<n;i++){ printf("%d,",a[i]); //輸出元素}printf("\n");} 編程題#include<stdio.h>#include<stdlib.h>voidFind(int*a,intn,int*max,int*maxPos,int*min,int*minPos);intmain(){intarray[10]={23,45,90,-9,43,90,4,2,-9};intmax,min,maxPos=0,minPos=0;Find(array,10,&max,&maxPos,&min,&minPos);printf("max=%d,maxPos=%d,min=%d,minPos=%d\n",max,maxPos,min,minPos);return0;}voidFind(int*a,intn,int*max,int*maxPos,int*min,int*minPos){inti;*max=*min=a[0];for(i=1;i<n;i++)if(a[i]>*max){*max=a[i];*maxPos=i;}elseif(a[i]<*min){*min=a[i];*minPos=i;}}12:八進(jìn)制轉(zhuǎn)換為二進(jìn)制#include<stdio.h>intOctToBin(intn,int*p){inti,r,k=0;while(n){ r=n%8;for(i=1;i<=3;i++) p[k++]=r%2;r=r/2;}n=n/8;}returnk;}intmain(){inti,n,array[30],k;scanf("%o",&n);k=OctToBin(n,array);while(array[k-1]==0)k--;for(i=k-1;i>=0;i--)printf("%d",array[i]);printf("\n");return0;}13:最大公約數(shù)。#include<stdio.h>intgcd(intm,int{intr;r=m%n;if(!r)returnn;else}
returngcd(n,r);intmain(){intm,n;do{ scanf("%d%d",&m,&n);}while(m<=0||n<=0);printf("gcd=%d\n",gcd(m,n));return0;}14:#include<stdio.h>#include<math.h>#defineS(a,b,c)((a)+(b)+(c))/2#defineAREA(s,a,b,c)sqrt((s)*((s)-(a))*((s)-(b))*((s)-(c)))intmain(){doublea,b,c,s,area;scanf("%lf%lf%lf",&a,&b,&c);if(a<=0||b<=0||c<=0||a+b<=c||a+c<=b||b+c<=a)printf("Error!Pleaseinputagain.\n");else{s=S(a,b,c);area=AREA(s,a,b,c);printf("Area=%.3lf\n",area);}return0;}15:。#include<stdio.h>#defineLEAP_YEAR(y)(y)%400==0||(y)%4==0&&(y)%100!=0intmain(){intyear;scanf("%d",&year);if(year>=10000||year<=999)printf("Inputerror!\n");else
if(LEAP_YEAR(year))printf("%disaleapyear!\n",year);elsereturn0;}
printf("%disnotaleapyear!\n",year);16#include<stdio.h>typedefstructStudent{intnum;charname[20];intscore;}STU;voidinput(STU*t,intn){inti;for(i=0;i<n;i++){scanf("%d",&t[i].num);getchar();scanf("%s",t[i].name);scanf("%d",&t[i].score);}}STU*average(STU*t,intn,double*ave){intSTU*high;for(i=0;i<n;i++)sum+=t[i].score;high=t;for(i=1;i<n;i++)if(t[i].score>high->score)high=t+i;*ave=sum*1.0/n;returnhigh;}intmain(){STUteam[3],*high=NULL;doubleave;input(team,3);high=average(team,3,&ave);printf("Theaveragescore=%.2f\n",ave);printf("Thestudentwhohasthehighestscoreis:\n");printf("%d\t%s\t%d\n",high->num,high->name,high->score);return0;}編程題17#include<stdio.h>enumSeasons{Spring,Summer,Autumn,Winter};structDate{intyear,month,day;};intmain(){structDated;enumSeasonss;scanf("%d%d%d",&d.year,&d.month,&d.day);if(d.month>=3&&d.month<=5)s=Spring;elseif(d.month>=6&&d.month<=8)s=Summer;elseif(d.month>=9&&d.month<=11)s=Autumn;elseif(d.month==12||d.month==1||d.month==2)s=Winter;switch(s){caseSpring:printf("NowitisSpring\n");break;caseSummer:printf("NowitisSummer\n");caseAutumn:printf("NowitisAutumn\n");break;caseWinter:printf("NowitisWinter\n");break;}return0;}18#include<stdio.h>intinput(char*s){inti=0;charc;do{c=getchar();if(c>='0'&&c<='9'||c>='A'&&c<='F'||c>='a'&&c<='f')s[i++]=c;elsereturn0;}while(i<4);s[i]='\0';return1;}intchange(char*s){intn=0,i=0;while(s[i]){if(s[i]>='0'&&s[i]<='9')n=n*16+(s[i]-48);elseif(s[i]>='A'&&s[i]<='F')n=n*16+(s[i]-55);elseif(s[i]>='a'&&s[i]<='f')n=n*16+(s[i]-87);i++;}returnn;}intmain(){chars[5]; //定義字符數(shù)組if(input(s)) //printf("Thedecdatais:%d\n",change(s));else //printf("Originaldataerror\n");return0;}19#include<stdio.h>#include<string.h>voidreverse(char*s){char*p=s,*q,t;intlen=strlen(s);q=p+len-1;while(p<q){t=*p;*p=*q;*q=t;p++;q--;}}intmain(){chars[100];gets(s);reverse(s);puts(s);return0;}20#include<stdio.h>intchange(char*source,char*des){inti=0;while(*source){if(*source>='0'&&*source<='9')des[i++]=*source;source++;}des[i]='\0';returni;}doublecalcu(char*s){doubleresult=0;while(*s){result=result*10+(*s-48);s++;}returnresult;}intmain(){charstr[50],strdes[50];gets(str);if(change(str,strdes))printf("%.4f\n",calcu(strdes));elseprintf("thedigitalstringisempty!\n");return0;21:打印楊輝三角形#include<stdio.h>intmain(){inty[10][10]={0},i,j,n;scanf("%d",&n);for(i=1;i<=n;i++)y[i][1]=y[i][i]=1;for(i=3;i<=n;i++)for(j=2;j<n;j++)y[i][j]=y[i-1][j-1]+y[i-1][j];for(i=1;i<=n;i++){for(j=1;j<=i;j++)printf("%5d",y[i][j]);printf("\n");}return
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024年水利水電建設(shè)項(xiàng)目合同
- 2024年度大米食用油品牌授權(quán)及區(qū)域代理合同3篇
- 忠誠(chéng)教育課程設(shè)計(jì)
- 2024年度國(guó)際貿(mào)易合同履行風(fēng)險(xiǎn)評(píng)估與應(yīng)對(duì)合同3篇
- 2024年房屋買(mǎi)賣(mài)居間合同法律咨詢(xún)3篇
- 港口客運(yùn)與船舶技術(shù)考核試卷
- 電工儀表的數(shù)據(jù)中心應(yīng)用考核試卷
- 林木育種中種源選擇與適應(yīng)性試驗(yàn)考核試卷
- 2024年未建好二手房買(mǎi)賣(mài)合同包含屋頂綠化及雨水收集利用協(xié)議3篇
- 2024年版住宅簡(jiǎn)易裝修租賃協(xié)議模板版B版
- 圖書(shū)管理系統(tǒng)畢業(yè)論文參考文獻(xiàn)精選,參考文獻(xiàn)
- 山區(qū)支教個(gè)人總結(jié)(3篇)
- 寫(xiě)字樓辦公設(shè)計(jì)注意要點(diǎn)課件
- 立體裁剪課件
- 內(nèi)容320neo教程正式版
- DB31T 685-2019 養(yǎng)老機(jī)構(gòu)設(shè)施與服務(wù)要求
- 風(fēng)機(jī)招標(biāo)技術(shù)要求
- 貸后跟蹤檢查表(定)
- 國(guó)家基層高血壓防治管理指南考核試題與答案
- 孫健敏 徐世勇組織行為學(xué)課后習(xí)題解答
- 高考?xì)v史二輪復(fù)習(xí)熱點(diǎn)主題二關(guān)注民生-構(gòu)建和諧社會(huì)“制度自信”讓生活更美好課件
評(píng)論
0/150
提交評(píng)論