綜合案例拓展源代碼_第1頁
綜合案例拓展源代碼_第2頁
綜合案例拓展源代碼_第3頁
綜合案例拓展源代碼_第4頁
綜合案例拓展源代碼_第5頁
已閱讀5頁,還剩49頁未讀 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

C#10011、2、3、4{inti,j,k;for(i=1;i<5;i++)/*以下為三重循環(huán)*/for{if(i!=k&&i!=j&&j!=k)*i、j、k*/}}2題目:企業(yè)的獎金根據(jù)利潤提成。利潤(I)低于或等于10萬元時,獎金可10%;利潤高10201010%107.5%;2040205%;4060403%;60100601.5%,高于1001001%I,求應(yīng)發(fā){longintintbonus1,bonus2,bonus4,bonus6,bonus10,bonus; elseif(i<=200000)elseif(i<=400000)elseif(i<=600000)elseif(i<= }310016810100268#include"math.h"{longintforx=sqrt(i+100);/*x100*/y=sqrt(i+268);/*y168}}43553{intday,month,year,sum,leap;printf("\npleaseinputyear,month,day\n");{case1:sum=0;break;case2:sum=31;break;case3:sum=59;break;case4:sum=90;break;case5:sum=120;break;case6:sum=151;break;case7:sum=181;break;case8:sum=212;break;case作者:zhlei812005-1-2211:292經(jīng)典C100case10:sum=273;break;case11:sum=304;break;casedefault:printf("data}sum=sum+day;/*再加上某天的天數(shù)*/if(leap==1&&month>2)/*2,總天數(shù)應(yīng)該加一天*/printf("Itisthe%dth5x,y,z,xxyx>yx與y然后再用xzx>zxzx{intx,y,z,t;if(x>y){t=x;x=y;y=t;}/*x,y*/{t=z;z=x;x=t;}/*x,z*/{t=y;y=z;z=t;}/*z,y*/printf("smalltobig:%d%dd\n",x,y,z);}6題目:用*號輸出字母C程序分析:可先用'*'C,#include"stdio.h"{printf("oC-world!\n");printf("****\n");printf("printf("*\n");printf("****\n");}7題目:輸出特殊圖案,請在cVery256#include"stdio.h"{chara=176,b=219;89*999,i,j#include"stdio.h"{inti,j,result;for{{printf("%d*%d=%-3d",i,j,result);/*-3d3}printf("\n");/*每一行后換行}}9i,ji+j#include"stdio.h"{inti,j;{printf("}}10i,jji#include"stdio.h"{int{}}作者:zhlei812005-1-2211:293回復(fù):經(jīng)典C100113{longf1,f2;inti;{printf("%12ldif(i%2==0)printf("\n");/*控制輸出,每行四個*/f1=f1+f2;/*前兩個月加起來賦值給第三個月*/f2=f1+f2;/*前兩個月加起來賦值給第三個月*/}}12101-200#include"math.h"{intm,i,k,h=0,leap=1;{k=sqrt(m+1);if(leap){printf("%-4d",m);h++;}}printf("\nThetotalis}13本身。例如:153153=1+53for100-999{intprintf("'waterflower'numberis:");{{printf("%-}}}1490,90=2*3*3*5程序分析:對nk,然后按下述步n,n<>k,nkknkn,nkk+1k2./*zhengintisdividedyinshu*/{intprintf("\npleaseinputanumber:\n");{{{printf("%d*",i);}}}15題目:利用條件運(yùn)算符的嵌套來完成此題:學(xué)習(xí)成績>=90A60-89B60C程序分析:(a>b)?a:b{intscore;charprintf("pleaseinputascore\n");printf("%dbelongsto%c",score,grade);}16題目:輸入兩個正整數(shù)mn,作者:zhlei812005-1-2211:304回復(fù):經(jīng)典C100{intprintf("pleaseinputtwonumbers:\n");if(num1{temp=num1;}while(b!=0)/*b0{}}17while#include"stdio.h"{charintletters=0,space=0,digit=0,others=0;printf("pleaseinputsomecharacters\n");{elseif(c=='')elseif(c>='0'&&c<='9')}printf("allinall:char=%dspace=%ddigit=%dothers=%d\n",letters,}18s=a+aa+aaa+aaaa+aa...aa 5{inta,n,count=1;longintsn=0,tn=0;printf("pleaseinputaandn\n");{}}19+2+3.1000{staticintk[10];inti,j,n,s;{n=-for(i=1;i{{}}{printf("%disawanshu",j);for(i=0;iprintf("%d,",k[i]);}}}201001010{floatsn=100.0,hn=sn/2;intn;{sn=sn+2*hn;/*n*/hn=hn/2;/*n*/}printf("thetotalofroadis%f\n",sn);printf("thetenthis%fmeter\n",hn);}21第二天早上又將剩下的桃子一半,又多吃了一個。以后每天早上都10{intday,x1,x2;{x1=(x2+1)*2;/*212*/day--}printf("thetotalis}22a,b,c比賽。有人向隊員打聽比賽的。a說他不和x比,c說他不x,z三隊賽手的{chari,j,k;/*iajbkc*/{{{printf("orderisa--%c\tb--%c\tc--}}}}23題目:打印出如下圖案(菱形** for{inti,j,k;{printf("");}{printf("");}}2420{intn,t,number=20;floata=2,b=1,s=0;{t=a;a=a+b;b=t;/*t}printf("sumis}251+2!+3!+...+20{floatn,s=0,t=1;{}}265!程序分析:遞歸#include"stdio.h"{intintfact();}intfact(j)intj;{intsum;returnsum;}275#include"stdio.h"{intvoidpalin(intn);}voidpalin(n)intn;{charnext;{}{}}28題目:有5個人坐在一起,問第五個人多少歲?他說比第4 2歲。問43個2歲。問第三個人,又說比第2兩歲。問第2個人,說比第一個兩歲。最后10第四人的歲數(shù),依次類推,推到第一人(10),int{intc;if(n==1)c=10;elsec=age(n-1)+2;}{}295專數(shù)002班提供)main(){longb=x%10000/1000;/*分解位*/if(a!=0)printf("thereare5,%ld%ld%ld%ld%ld\n",e,d,c,b,a);elseif(b!=0)printf("thereare4,%ld%ld%ld%ld\n",e,d,c,b);elseif(c!=0)printf("thereare3,%ld%ld%ld\n",e,d,c);elseif(d!=0)printf("thereare2,%ld%ld\n",e,d);elseif(e!=0)printf("thereare1,%ld\n",e);}3051232129main(){longge,shi,qian,wan,x;if(ge==wan&&shi==qian)/*個位等于萬位并且十位等于千位*/printf("thisnumberisahuiwen\n");printf("thisnumberisnota}31ifvoid{charprintf("pleaseinputthefirstletterofsomeday\n");while((letter=getch())!='Y')/*Y*/{switch{case'S':printf("pleaseinputsecondletter\n");elseif((letter=getch())=='u')elseprintf("dataerror\n");case'F':printf("friday\n");break;casecase'T':printf("pleaseinputsecondletter\n");elseifelseprintf("dataerror\n");case'W':printf("wednesday\n");break;default:printf("dataerror\n");}}}32題目:Pressanykeytochangecolor,doyouwanttotryit.Pleasehurryup!void{intfor(color=0;color<8;{cprintf("Thisiscolor%d\r\n",color);cprintf("Pressanykeytocontinue\r\n");}}33gotoxy()clrscr()void{gotoxy(1,5);/*定位函數(shù)*/cprintf("Outputatrow5column1\n");gotoxy(20,cprintf("Outputatrow10column}34void{printf("o,}voidthree_{intfor(counter1;counter3;counter++)}void{three_os();/*調(diào)用此函數(shù)}35void{intfor(color=1;color<16;{cprintf("Thisiscolord\r\n",color);}textcolor(128+15);cprintf("Thisisblinking\r\n");}36100#include"math.h"#defineN101{inti,j,line,a[N];for(i=2;ifor(i=2;ifor(j=i+1;j{}}371098#defineN10{int/*inputprintf("pleaseinputtennum:\n");/*sorttennum*/for(j=i+1;jif(a[min]>a[j])min=j;}/*outputdata*/printf("Aftersorted\n");}38題目:求一個3*3矩陣對角線元程序分析:利重for循環(huán)控制輸入二維數(shù)組,再將a[i][i]累加后輸{floata[3][3],sum=0;inti,j;printf("pleaseinputrectangleelement:\n");printf("duijiaoxianheis}39此元后的數(shù),依次后移一個位置{intinttemp1,temp2,number,end,i,j;printf("originalarrayis:\n");printf("insertanewnumber:");{}}}}}40#defineN5{inta[N]={9,6,5,4,1},i,temp;printf("\noriginalarray:\n");for(i=0;iprintf("%4d",a[i]);for(i=0;i{temp=a[i];a[i]=a[N-i-a[N-i-}printf("\nsortedarray:\n");for(i=0;i}41static#include"stdio.h"{intstaticintstatic_var=0;printf("\40:varequal%d\n",var);printf("\40:staticvarequal%d\n",static_var);}void{inti;}42auto#include"stdio.h"{inti,num;for{printf("\40:Thenumequal%d\n",num);{autointprintf("\40:Theinternalblocknumequal%d\n",num);}}}43static#include"stdio.h"{inti,num;{printf("\40:Thenumequal%d\n",num);{staticintprintf("\40:Theinternalblocknumequal%d\n",num);}}}44external#include"stdio.h"inta,b,c;void{inta;}void{printf("Thevalueofcisequalto}45registervoidmain(){registerinti;inttmp=0;printf("Thesumis}46題目:宏#define#include"stdio.h"#defineTRUE1#defineFALSE0#defineSQ(x)(x)*(x)voidmain(){intintprintf("\40:Programwillstopifinputvaluelessthan50.\n");{printf("\40:Pleaseinputnumber==>");printf("\40:Thesquareforthisnumberis%d\n",SQ(num));}}47題目:宏#define#include"stdio.h"#defineexchange(a,b)/*宏定義中允許包含兩道衣裳命令的情形,此時intt;\}void{intx=10;intprintf("x=%d;y=%d\n",x,y);printf("x=%d;y=%d\n",x,y);}48題目:宏#define#defineLAG>#defineSMA<#defineEQ==#include"stdio.h"void{inti=10;intj=20;if(iLAGj)printf("\40:%dlargerthan%d\n",i,j);elseif(iEQj)printf("\40:%dequalto%d\n",i,j);elseif(iSMAj)printf("\40:%dsmallerthan%d\n",i,j);printf("\40:Nosuch}49題目:#if#ifdef#ifndef#include"stdio.h"#defineMAX#defineUM(x,y)(x>y)?x:y#defineMINIMUM(x,y)(x>y)?y:xvoidmain(){inta=10,b=20;#ifdefMAXprintf("\40:Thelargeroneis%d\n",UM(a,b));printf("\40:Theloweroneis%d\n",MINIMUM(a,b));#ifndefprintf("\40:Theloweroneis%d\n",MINIMUM(a,b));printf("\40:Thelargeroneis%d\n",UM(a,b));#undefMAX#ifdefprintf("\40:Thelargeroneis%d\n",UM(a,b));printf("\40:Theloweroneis%d\n",MINIMUM(a,b));#defineMIN#ifndefprintf("\40:Theloweroneis%d\n",MINIMUM(a,b));printf("\40:Thelargeroneis%d\n",}50題目:#includetest.h#defineLAG>#defineSMA<#defineEQ==#include"test.h"/*50.c,test.h*/#include"stdio.h"void{inti=10;intj=20;if(iLAGj)printf("\40:%dlargerthan%d\n",i,j);elseif(iEQj)printf("\40:%dequalto%d\n",i,j);elseif(iSMAj)printf("\40:%dsmallerthan%d\n",i,j);printf("\40:Nosuch}51題目:學(xué)習(xí)使用按位與&程序分析:0&0=0;0&1=0;1&0=0;#include"stdio.h"{inta,b;printf("\40:Thea&b(decimal)is%d\n",b);printf("\40:Thea&b(decimal)is%d}52題目:學(xué)習(xí)使用按位或|程序分析:0|0=0;0|1=1;1|0=1;#include"stdio.h"{inta,b;printf("\40:Thea&b(decimal)is%d\n",b);printf("\40:Thea&b(decimal)is%d}53題目:學(xué)習(xí)使用按位異或^程序分析:0^0=0;0^1=1;1^0=1;#include"stdio.h"{inta,b;printf("\40:Thea&b(decimal)is%d\n",b);printf("\40:Thea&b(decimal)is%d}54題目:取一個整數(shù)a4~7a441,0~(~0<<4){unsigneda,b,c,d;}55題目:學(xué)習(xí)使用按位取反~程序分析:~0=1;#include"stdio.h"{inta,b;printf("\40:Thea's1complement(decimal)is%d\n",b);printf("\40:Thea's1complement(hexidecimal)is%x}56circle#include"graphics.h"{intdriver,mode,i;floatj=1,k=1;{}}57line#include"graphics.h"{intdriver,mode,i;floatx0,y0,y1,x1;floatj=12,k;{{y1=y1-}}58rectanglefor100-999#include"graphics.h"{intx0,y0,y1,x1,driver,mode,i;{}outtextxy(150,40,"Howbeautifulitis!");}59#definePAI3.defineB0.809#include"graphics.h"#include"math.h"{inti,j,k,x0,y0,x,y,driver,mode;floata;{setcolor(2);line(x0,y0,x,y);}/*Make0timenormalsizeletters*/outtextxy(10,170,"pressakey");{{setcolor(2);line(x0,y0,x,y);}{a=(2*PAI/16)*i+(2*PAI/180)*k-}}}60#include"graphics.h"#defineLEFT0#defineTOP#defineRIGHT#defineBOTTOM#defineLINES#defineMAXCOLOR15{intdriver,mode,error;intx1,y1;intintdx1,dy1,dx2,dy2,i=1;intcount=0;intcolor=0;{{}}}61題目:打印出三角形(要求打印出10行如下圖111210105{intintfor(j=1;ja[i][j]=a[i-1][j-1]+a[i-1][j];}}62putpixel#include"stdio.h"#include"graphics.h"{inti,j,driver=VGA,mode=VGAHI;}63#include"stdio.h"#include"graphics.h"#include"conio.h"{intx=360,y=160,driver=VGA,mode=VGAHI;intnum=20,i;inttop,bottom;}}64題目:利用ellipseandrectangle#include"stdio.h"#include"graphics.h"#include"conio.h"{intdriver=VGA,mode=VGAHI;inti,num=15,top=50;intleft=20,right=50;}}65#include"graphics.h"#include"math.h"#include"dos.h"#include"conio.h"#include"stdlib.h"#include"stdio.h"#include"stdarg.h"#defineMAXPTS15#definePI3.structPTS{intx,y;void{structviewporttypestructPTSpoints[MAXPTS];inti,j,h,w,xcenter,ycenter;intradius,angle,step;doubleprintf("MoveTo/LineToDemonstration");getviewsettings(&vp);h=vp.bottom-vp.top;w=vp.right-vp.left;xcenter=w/2;/*Determinethecenterofcircle*/ycenter=h/2;radius=(h-30)/(AspectRatio*step=360/MAXPTS;/*Determine#ofincrements*/angle=0;/*Beginatzerodegrees*/for(i=0;irads=(double)angle*PI/180.0;/*Convertangletoradians*/points[i].x=xcenter+(int)(cos(rads)*radius);points[i].y=ycenter-(int)(sin(rads)*radius*AspectRatio);angle+=step;/*Movetonextincrement*/}circle(xcenter,ycenter,radius);/*Drawboundingcirclefor(i=0;ifor(j=i;jmoveto(points[i].x,points[i].y);/*Movetobeginningofcord*/lineto(points[j].x,points[j].y);/*Drawthecord*/}}{intdriver,mode;663個數(shù)a,b,c{intint*pointer1,*pointer2,*pointer3;printf("pleaseinput3number:n1,n2,n3:");if(n1>n2)swap(pointer1,pointer2);if(n1>n3)swap(pointer1,pointer3);if(n2>n3)printf("thesortednumbers}int{intp;}67{intnumber[10];}intnumber[10];{inti;}intarray[10];{int*max,*min,k,l;int*p,*arr_end;for(p=array+1;pif(*p>*max)max=p;elseif(*p<*min)min=p;}int{intfor(p=array;pprintf("%d,",*p);}68{intnumber[20],n,m,i;printf("thetotalnumbersis:");printf("backfor(i=0;ifor(i=0;i}int{int*p,array_end;if(m>0)}69n個人圍成一圈,順序排號。從第一個人開始報數(shù)(13報數(shù)3的#definenmax50{intprintf("pleaseinputthetotalofnumbers:");for(i=0;i*(p+i)=i+1;while(m{if(*(p+i)!=0)k++;{*(p+i)=0;if(i==n)}while(*p==0)p++;printf("%disleft\n",*p);}70{intcharprintf("pleaseinputastring:\n");printf("thestringhas%d}char*p;{intn;}return}71#defineN5structstudent{charnum[6];charname[8];intscore[4];}stu[N];structstudent{intfor(i=0;i{printf("\npleaseinput%dof%d\n",i+1,N);printf("num:");printf("name:");{printf("score}}}structstudent{intprintf("\nNo.NameSco1Sco2for(i=0;i{printf("%-6s%-10s",stu[i].num,stu[i].name);}}{}72/*creatalist*/#include"stdlib.h"#include"stdio.h"structlist{intdata;structlist*next;typedefstructlistnode;typedefnode*link;voidmain(){linkptr,head;intnum,i;printf("pleaseinput5numbers==>\n");{if(i==4)ptr->next=NULL;}{printf("Thevalueis==>%d\n",ptr->data);}}73/*reverseoutputalist*/#include"stdlib.h"#include"stdio.h"struct{intdata;structlist*next;typedefstructlistnode;typedefnode*link;voidmain(){linkptr,head,tail;intnum,i;printf("\npleaseinput5data==>\n");{}{printf("Thevalueis==>%d\n",ptr->data);74#include"stdlib.h"#include"stdio.h"structlist{intdata;structlist*next;typedefstructlistnode;typedefnode*link;linkdelete_node(linkpointer,link{if(tmp==NULL)/*deletefirstnode*/returnpointer->next;{if(tmp->next->next==NULL)/*deletelastelse/*deletetheothernode*/returnpointer;}}voidselection_sort(linkpointer,int{linktmp,btmp;inti,min;for(i=0;i{}}printf("\40:%d\n",min);}}linkcreate_list(intarray[],int{linktmp1,tmp2,pointer;inti;for(i=1;i{tmp2=(link)malloc(sizeof(node));}return}linkconcatenate(linkpointer1,link{linktmp;return}void{intlinkptr;}75{inti,n;{printf("zhuhaoshide}}76n1/2+1/4+...+1/n,當(dāng)輸入n為奇數(shù)時,調(diào)#include"stdio.h"{floatpeven(),podd(),dcall();floatsum;intwhile{{}{}}floatpeven(int{floats;inti;}floatpodd(n)intn;{floats;inti;}floatdcall(fp,n)float(*fp)();intn;{floats;}77{char*s[]={"man","woman","girl","boy","sister"};char**q;intk;*這里填寫什么語句}}78#defineN4#include"stdio.h"staticstructman{charname[20];intage;}[N]={"li",18,"wang",19,"zhang",20,"sun",22};{structman*q,*p;inti,m=0; for(i=0;i{if(mage)}79{char*str1[20],*str2[20],*str3[20];charswap();printf("pleaseinputthreestrings\n");if(strcmp(str1,str2)>0)swap(str1,str2);if(strcmp(str1,str3)>0)swap(str1,str3);if(strcmp(str2,str3)>0)swap(str2,str3);printf("afterbeingsorted\n");}charswap(p1,p2)char*p1,*p2;{char*p[20];}80{inti,m,j,k,count;{count=0;{}}}81數(shù)。求??809*??后的結(jié)果。output(longb,longi){}{longinta,b,i;output(b,i);}}82{char*p,s[6];intn;}83{longsum=4,s=4;intj;for(j=2;j<=8;j++)/*jisceof{printf("\n%ld",sum);}84#include"stdio.h"#include"math.h"{int{for(c=2;c<=sqrt(b);c++)if(b%c==0)break;if(d%c==0)break;}}859{longintm9=9,sum=9;intzi,n1=1,c9=1;{if(!(sum%zi))}}printf("%ld,canbedividedby%d}86#include"stdio.h"{chara[]="acegikm";charb[]="bdfhjlnpq";charc[80],*p;inti=0,j=0,

溫馨提示

  • 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)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論