关闭

关闭

关闭

封号提示

内容

首页 C语言经典语句.doc

C语言经典语句.doc

C语言经典语句.doc

上传者: 谎言弥漫的冷漠世界 2017-09-30 评分 0 0 0 0 0 0 暂无简介 简介 举报

简介:本文档为《C语言经典语句doc》,可适用于IT/计算机领域,主题内容包含C语言经典语句C语言经典程序()发表日期:::【程序】题目:有、、、个数字能组成多少个互不相同且无重复数字的三位数,都是多少,程序分析:可填在百位、符等。

C语言经典语句C语言经典程序()发表日期:::【程序】题目:有、、、个数字能组成多少个互不相同且无重复数字的三位数,都是多少,程序分析:可填在百位、十位、个位的数字都是、、、。组成所有的排列后再去掉不满足条件的排列。程序源代码:main(){inti,j,kprintf("n")for(i=i<i),*以下为三重循环*for(j=j<j)for(k=k<k){if(i!=ki!=jj!=k)*确保i、j、k三位互不相同*printf("d,d,dn",i,j,k)}}==============================================================【程序】题目:企业发放的奖金根据利润提成。利润(I)低于或等于万元时奖金可提利润高于万元低于万元时低于万元的部分按提成高于万元的部分可可提成万到万之间时高于万元的部分可提成万到万之间时高于万元的部分可提成万到万之间时高于万元的部分可提成高于万元时超过万元的部分按提成从键盘输入当月利润I求应发放奖金总数,程序分析:请利用数轴来分界定位。注意定义时需把奖金定义成长整型。程序源代码:main(){longintiintbonus,bonus,bonus,bonus,bonus,bonusscanf("ld",i)bonus=*bonus=bonus*bonus=bonus*bonus=bonus*bonus=bonus*if(i<=)bonus=i*elseif(i<=)bonus=bonus(i)*elseif(i<=)bonus=bonus(i)*elseif(i<=)bonus=bonus(i)*elseif(i<=)bonus=bonus(i)*elsebonus=bonus(i)*printf("bonus=d",bonus)}==============================================================【程序】题目:一个整数它加上后是一个完全平方数再加上又是一个完全平方数请问该数是多少,程序分析:在万以内判断先将该数加上后再开方再将该数加上后再开方如果开方后的结果满足如下条件即是结果。请看具体分析:程序源代码:#include"mathh"main(){longinti,x,y,zfor(i=i<i){x=sqrt(i)*x为加M(a,b))#elseprintf(":Theloweroneisdn",MINIMUM(a,b))#endif#defineMIN#ifndefMINprintf(":Theloweroneisdn",MINIMUM(a,b))#elseprintf(":Thelargeroneisdn",MAXIMUM(a,b))#endif}==============================================================【程序】题目:#include的应用练习程序分析:程序源代码:testh文件如下:#defineLAG>#defineSMA<#defineEQ==#include"testh"*一个新文件c包含testh*#include"stdioh"voidmain(){inti=intj=if(iLAGj)printf(":dlargerthandn",i,j)elseif(iEQj)printf(":dequaltodn",i,j)elseif(iSMAj)printf(":dsmallerthandn",i,j)elseprintf(":Nosuchvaluen")}经典C语言程序()发表日期:::【程序】题目:学习使用按位与。程序分析:====程序源代码:#include"stdioh"main(){inta,ba=b=aprintf(":Theab(decimal)isdn",b)b=printf(":Theab(decimal)isdn",b)}==============================================================【程序】题目:学习使用按位或|。程序分析:|=|=|=|=程序源代码:#include"stdioh"main(){inta,ba=b=a|printf(":Theab(decimal)isdn",b)b|=printf(":Theab(decimal)isdn",b)}==============================================================【程序】题目:学习使用按位异或^。程序分析:^=^=^=^=程序源代码:#include"stdioh"main(){inta,ba=b=a^printf(":Theab(decimal)isdn",b)b^=printf(":Theab(decimal)isdn",b)}==============================================================【程序】题目:取一个整数a从右端开始的,位。程序分析:可以这样考虑:()先使a右移位。()设置一个低位全为,其余全为的数。可用~(~<<)()将上面二者进行运算。程序源代码:main(){unsigneda,b,c,dscanf("o",a)b=a>>c=~(~<<)d=bcprintf("onon",a,d)}==============================================================【程序】题目:学习使用按位取反~。程序分析:~=~=程序源代码:#include"stdioh"main(){inta,ba=b=~aprintf(":Thea'scomplement(decimal)isdn",b)a=~aprintf(":Thea'scomplement(hexidecimal)isxn",a)}==============================================================【程序】题目:画图学用circle画圆形。程序分析:程序源代码:*circle*#include"graphicsh"main(){intdriver,mode,ifloatj=,k=driver=VGAmode=VGAHIinitgraph(driver,mode,"")setbkcolor(YELLOW)for(i=i<=i){setcolor()circle(,,k)k=kjj=j}}==============================================================【程序】题目:画图学用line画直线。程序分析:程序源代码:#include"graphicsh"main(){intdriver,mode,ifloatx,y,y,xfloatj=,kdriver=VGAmode=VGAHIinitgraph(driver,mode,"")setbkcolor(GREEN)x=y=y=x=for(i=i<=i){setcolor()line(x,y,x,y)x=xy=yx=xy=yj=j}x=y=y=for(i=i<=i){setcolor()line(x,y,x,y)x=xy=yy=y}}==============================================================【程序】题目:画图学用rectangle画方形。程序分析:利用for循环控制个数每个数分解出个位十位百位。程序源代码:#include"graphicsh"main(){intx,y,y,x,driver,mode,idriver=VGAmode=VGAHIinitgraph(driver,mode,"")setbkcolor(YELLOW)x=y=y=x=for(i=i<=i){setcolor()rectangle(x,y,x,y)x=xy=yx=xy=y}settextstyle(DEFAULTFONT,HORIZDIR,)outtextxy(,,"Howbeautifulitis!")line(,,,)setcolor()circle(,,)}==============================================================【程序】题目:画图综合例子。程序分析:程序源代码:#definePAI#defineB#include"graphicsh"#include"mathh"main(){inti,j,k,x,y,x,y,driver,modefloatadriver=CGAmode=CGACinitgraph(driver,mode,"")setcolor()setbkcolor(GREEN)x=y=circle(x,y,)circle(x,y,)circle(x,y,)for(i=i<i){a=(*PAI)*ix=ceil(x*cos(a))y=ceil(y*sin(a)*B)setcolor()line(x,y,x,y)}setcolor()circle(x,y,)*Maketimenormalsizeletters*settextstyle(DEFAULTFONT,HORIZDIR,)outtextxy(,,"pressakey")getch()setfillstyle(HATCHFILL,YELLOW)floodfill(,,WHITE)getch()for(k=k<=k){setcolor()for(i=i<=i){a=(*PAI)*i(*PAI)*kx=ceil(x*cos(a))y=ceil(ysin(a)*B)setcolor()line(x,y,x,y)}for(j=j<=j){a=(*PAI)*i(*PAI)*kx=ceil(x*cos(a))y=ceil(y*sin(a)*B)line(x,y,x,y)}}restorecrtmode()}==============================================================【程序】题目:画图综合例子。程序分析:程序源代码:#include"graphicsh"#defineLEFT#defineTOP#defineRIGHT#defineBOTTOM#defineLINES#defineMAXCOLORmain(){intdriver,mode,errorintx,yintx,yintdx,dy,dx,dy,i=intcount=intcolor=driver=VGAmode=VGAHIinitgraph(driver,mode,"")x=x=y=y=dx=dy=dx=dy=while(!kbhit()){line(x,y,x,y)x=dxy=dyx=dxydyif(x<=LEFT||x>=RIGHT)dx=dxif(y<=TOP||y>=BOTTOM)dy=dyif(x<=LEFT||x>=RIGHT)dx=dxif(y<=TOP||y>=BOTTOM)dy=dyif(count>LINES){setcolor(color)color=(color>=MAXCOLOR):color}}closegraph()}经典C语言程序()发表日期:::【程序】题目:打印出杨辉三角形(要求打印出行如下图)程序分析:程序源代码:main(){inti,jintaprintf("n")for(i=i<i){ai=aii=}for(i=i<i)for(j=j<ij)aij=aijaijfor(i=i<i){for(j=j<=ij)printf("",aij)printf("n")}}==============================================================【程序】题目:学习putpixel画点。程序分析:程序源代码:#include"stdioh"#include"graphicsh"main(){inti,j,driver=VGA,mode=VGAHIinitgraph(driver,mode,"")setbkcolor(YELLOW)for(i=i<=i=)for(j=j<=j)putpixel(i,j,)for(j=j<=j=)for(i=i<=i)putpixel(i,j,)}==============================================================【程序】题目:画椭圆ellipse程序分析:程序源代码:#include"stdioh"#include"graphicsh"#include"conioh"main(){intx=,y=,driver=VGA,mode=VGAHIintnum=,iinttop,bottominitgraph(driver,mode,"")top=ybottom=yfor(i=i<numi){ellipse(,,,,top,bottom)top=bottom=}getch()}==============================================================【程序】题目:利用ellipseandrectangle画图。程序分析:程序源代码:#include"stdioh"#include"graphicsh"#include"conioh"main(){intdriver=VGA,mode=VGAHIinti,num=,top=intleft=,right=initgraph(driver,mode,"")for(i=i<numi){ellipse(,,,,right,left)ellipse(,,,,,top)rectangle(*i,*i,*(i),*(i))right=left=top=}getch()}==============================================================【程序】题目:一个最优美的图案。程序分析:程序源代码:#include"graphicsh"#include"mathh"#include"dosh"#include"conioh"#include"stdlibh"#include"stdioh"#include"stdargh"#defineMAXPTS#definePIstructPTS{intx,y}doubleAspectRatio=voidLineToDemo(void){structviewporttypevpstructPTSpointsMAXPTSinti,j,h,w,xcenter,ycenterintradius,angle,stepdoubleradsprintf("MoveToLineToDemonstration")getviewsettings(vp)h=vpbottomvptopw=vprightvpleftxcenter=w*Determinethecenterofcircle*ycenter=hradius=(h)(AspectRatio*)step=MAXPTS*Determine#ofincrements*angle=*Beginatzerodegrees*for(i=i<MAXPTSi){*Determinecircleintercepts*rads=(double)angle*PI*Convertangletoradians*pointsix=xcenter(int)(cos(rads)*radius)pointsiy=ycenter(int)(sin(rads)*radius*AspectRatio)angle=step*Movetonextincrement*}circle(xcenter,ycenter,radius)*Drawboundingcircle*for(i=i<MAXPTSi){*Drawthecordstothecircle*for(j=ij<MAXPTSj){*Foreachremainingintersect*moveto(pointsix,pointsiy)*Movetobeginningofcord*lineto(pointsjx,pointsjy)*Drawthecord*}}}main(){intdriver,modedriver=CGAmode=CGACinitgraph(driver,mode,"")setcolor()setbkcolor(GREEN)LineToDemo()}经典C语言程序()发表日期:::【程序】题目:编写input()和output()函数输入输出个学生的数据记录。程序分析:程序源代码:#defineNstructstudent{charnumcharnameintscore}stuNinput(stu)structstudentstu{inti,jfor(i=i<Ni){printf("npleaseinputdofdn",i,N)printf("num:")scanf("s",stuinum)printf("name:")scanf("s",stuiname)for(j=j<j){printf("scored",j)scanf("d",stuiscorej)}printf("n")}}print(stu)structstudentstu{inti,jprintf("nNoNameScoScoScon")for(i=i<Ni){printf("ss",stuinum,stuiname)for(j=j<j)printf("d",stuiscorej)printf("n")}}main(){input()print()}==============================================================【程序】题目:创建一个链表。程序分析:程序源代码:*creatalist*#include"stdlibh"#include"stdioh"structlist{intdatastructlist*next}typedefstructlistnodetypedefnode*linkvoidmain(){linkptr,headintnum,iptr=(link)malloc(sizeof(node))ptr=headprintf("pleaseinputnumbers==>n")for(i=i<=i){scanf("d",num)ptr>data=numptr>next=(link)malloc(sizeof(node))if(i==)ptr>next=elseptr=ptr>next}ptr=headwhile(ptr!=){printf("Thevalueis==>dn",ptr>data)ptr=ptr>next}}==============================================================【程序】题目:反向输出一个链表。程序分析:程序源代码:*reverseoutputalist*#include"stdlibh"#include"stdioh"structlist{intdatastructlist*next}typedefstructlistnodetypedefnode*linkvoidmain(){linkptr,head,tailintnum,itail=(link)malloc(sizeof(node))tail>next=ptr=tailprintf("npleaseinputdata==>n")for(i=i<=i){scanf("d",num)ptr>data=numhead=(link)malloc(sizeof(node))head>next=ptrptr=head}ptr=ptr>nextwhile(ptr!=){printf("Thevalueis==>dn",ptr>data)ptr=ptr>next}}==============================================================【程序】题目:连接两个链表。程序分析:程序源代码:#include"stdlibh"#include"stdioh"structlist{intdatastructlist*next}typedefstructlistnodetypedefnode*linklinkdeletenode(linkpointer,linktmp){if(tmp==)*deletefirstnode*returnpointer>nextelse{if(tmp>next>next==)*deletelastnode*tmp>next=else*deletetheothernode*tmp>next=tmp>next>nextreturnpointer}}voidselectionsort(linkpointer,intnum){linktmp,btmpinti,minfor(i=i<numi){tmp=pointermin=tmp>databtmp=while(tmp>next){if(min>tmp>next>data){min=tmp>next>databtmp=tmp}tmp=tmp>next}printf(":dn",min)pointer=deletenode(pointer,btmp)}}linkcreatelist(intarray,intnum){linktmp,tmp,pointerintipointer=(link)malloc(sizeof(node))pointer>data=arraytmp=pointerfor(i=i<numi){tmp=(link)malloc(sizeof(node))tmp>next=tmp>data=arrayitmp>next=tmptmp=tmp>next}returnpointer}linkconcatenate(linkpointer,linkpointer){linktmptmp=pointerwhile(tmp>next)tmp=tmp>nexttmp>next=pointerreturnpointer}voidmain(void){intarr={,,,,}linkptrptr=createlist(arr,)selectionsort(ptr,)}==============================================================【程序】题目:放松一下算一道简单的题目。程序分析:程序源代码:main(){inti,nfor(i=i<i){n=if(i!=)n=nif(i==)n=nif(i==)n=nif(i!=)n=nif(n==)printf("zhuhaoshideshi:c",i)}}==============================================================【程序】题目:编写一个函数输入n为偶数时调用函数求n,当输入n为奇数时调用函数n(利用指针函数)程序分析:程序源代码:main()#include"stdioh"main(){floatpeven(),podd(),dcall()floatsumintnwhile(){scanf("d",n)if(n>)break}if(n==){printf("Even=")sum=dcall(peven,n)}else{printf("Odd=")sum=dcall(podd,n)}printf("f",sum)}floatpeven(intn){floatsintis=for(i=i<=ni=)s=(float)ireturn(s)}floatpodd(n)intn{floatsintis=for(i=i<=ni=)s=(float)ireturn(s)}floatdcall(fp,n)float(*fp)()intn{floatss=(*fp)(n)return(s)}==============================================================【程序】题目:填空练习(指向指针的指针)程序分析:程序源代码:main(){char*s={"man","woman","girl","boy","sister"}char**qintkfor(k=k<k){*这里填写什么语句*printf("sn",*q)}}==============================================================【程序】题目:找到年龄最大的人并输出。请找出程序中有什么问题。程序分析:程序源代码:#defineN#include"stdioh"staticstructman{charnameintage}personN={"li",,"wang",,"zhang",,"sun",}main(){structman*q,*pinti,m=p=personfor(i=i<Ni){if(m<p>age)q=pm=q>age}printf("s,d",(*q)name,(*q)age)}==============================================================【程序】题目:字符串排序。程序分析:程序源代码:main(){char*str,*str,*strcharswap()printf("pleaseinputthreestringsn")scanf("s",str)scanf("s",str)scanf("s",str)if(strcmp(str,str)>)swap(str,str)if(strcmp(str,str)>)swap(str,str)if(strcmp(str,str)>)swap(str,str)printf("afterbeingsortedn")printf("snsnsn",str,str,str)}charswap(p,p)char*p,*p{char*pstrcpy(p,p)strcpy(p,p)strcpy(p,p)}==============================================================【程序】题目:海滩上有一堆桃子五只猴子来分。第一只猴子把这堆桃子凭据分为五份多了一个这只猴子把多的一个扔入海中拿走了一份。第二只猴子把剩下的桃子又平均分成五份又多了一个它同样把多的一个扔入海中拿走了一份第三、第四、第五只猴子都是这样做的问海滩上原来最少有多少个桃子,程序分析:程序源代码:main(){inti,m,j,k,countfor(i=i<i=){count=m=ifor(k=k<k){j=i*i=jif(j==)countelsebreak}i=mif(count==){printf("dn",count)break}}}经典C语言程序()发表日期:::【程序】题目:时间函数举例程序分析:程序源代码:#include"stdioh"#include"timeh"voidmain(){timetlt*definealonginttimevarible*lt=time()*systemtimeanddate*printf(ctime(<))*englishformatoutput*printf(asctime(localtime(<)))*tranfertotm*printf(asctime(gmtime(<)))*tranfertoGreenwichtime*}==============================================================【程序】题目:时间函数举例程序分析:程序源代码:*calculatetime*#include"timeh"#include"stdioh"main(){timetstart,endintistart=time()for(i=i<i){printf("n")}end=time()printf(":Thedifferentisfn",difftime(end,start))}==============================================================【程序】题目:时间函数举例程序分析:程序源代码:*calculatetime*#include"timeh"#include"stdioh"main(){clocktstart,endintidoublevarstart=clock()for(i=i<i){printf("n")}end=clock()printf(":Thedifferentisfn",(double)(endstart))}==============================================================【程序】题目:时间函数举例,一个猜数游戏判断一个人反应快慢。(版主初学时编的)程序分析:程序源代码:#include"timeh"#include"stdlibh"#include"stdioh"main(){charcclocktstart,endtimeta,bdoublevarinti,guesssrand(time())printf("doyouwanttoplayit('y'or'n')n")loop:while((c=getchar())=='y'){i=rand()printf("npleaseinputnumberyouguess:n")start=clock()a=time()scanf("d",guess)while(guess!=i){if(guess>i){printf("pleaseinputalittlesmallern")scanf("d",guess)}else{printf("pleaseinputalittlebiggern")scanf("d",guess)}}end=clock()b=time()printf(":Ittookyoufsecondsn",var=(double)(endstart))printf(":ittookyoufsecondsnn",difftime(b,a))if(var<)printf("Youareveryclever!nn")elseif(var<)printf("youarenormal!nn")elseprintf("youarestupid!nn")printf("Congradulationsnn")printf("Thenumberyouguessisd",i)}printf("ndoyouwanttotryitagain("yy"or"n")n")if((c=getch())=='y')gotoloop}==============================================================【程序】题目:家庭财务管理小程序程序分析:程序源代码:*moneymanagementsystem*#include"stdioh"#include"dosh"main(){FILE*fpstructdatedfloatsum,chm=intlen,i,j=intccharch="",ch="",chtime="",chshop,chmoneypp:clrscr()sum=gotoxy(,)printf("||")gotoxy(,)printf("|moneymanagementsystem(C)|")gotoxy(,)printf("||")gotoxy(,)printf("|moneyrecords|todaycostlist|")gotoxy(,)printf("|||")gotoxy(,)printf("|date:||")gotoxy(,)printf("|||||")gotoxy(,)printf("|||")gotoxy(,)printf("|thgs:||")gotoxy(,)printf("|||||")gotoxy(,)printf("|||")gotoxy(,)printf("|cost:||")gotoxy(,)printf("|||||")gotoxy(,)printf("|||")gotoxy(,)printf("|||")gotoxy(,)printf("|||")gotoxy(,)printf("|||")gotoxy(,)printf("|||")gotoxy(,)printf("|||")gotoxy(,)printf("|||")gotoxy(,)printf("|||")gotoxy(,)printf("|||")gotoxy(,)printf("||")i=getdate(d)sprintf(chtime,"Mdd",ddayear,ddamon,ddaday)for(){gotoxy(,)printf("TabbrowsecostlistEscquit")gotoxy(,)printf("")gotoxy(,)printf("")gotoxy(,)printf("s",chtime)j=ch=getch()if(ch==)breakstrcpy(chshop,"")strcpy(chmoney,"")if(ch==){mm:i=fp=fopen("homedat","r")gotoxy(,)printf("")gotoxy(,)printf("listrecords")gotoxy(,)printf("||")gotoxy(,)printf("")gotoxy(,)printf("|")while(fscanf(fp,"ssfn",chtime,chshop,chm)!=EOF){if(i==){getch()i=}if((i)<){gotoxy(,i)printf("")gotoxy(,i)}elseif((i)>){gotoxy(,i)printf("")gotoxy(,i)}isum=sumchmprintf("ssfn",chtime,chshop,chm)}gotoxy(,)printf("||")gotoxy(,)printf("||")gotoxy(,)printf("||")gotoxy(,)printf("totalisf$",sum)fclose(fp)gotoxy(,)printf("pressanykeyto")getch()gotopp}else{while(ch!='r'){if(j<){strncat(chtime,ch,)j}if(ch==){len=strlen(chtime)if(j>){len=lenj=}strcpy(ch,"")j=jstrncat(ch,chtime,len)strcpy(chtime,"")strncat(chtime,ch,len)gotoxy(,)printf("")}gotoxy(,)printf("s",chtime)ch=getch()if(ch==)gotommif(ch==)exit()}gotoxy(,)printf("")gotoxy(,)j=ch=getch()while(ch!='r'){if(j<){strncat(chshop,ch,)j}if(ch==){len=strlen(chshop)strcpy(ch,"")j=jstrncat(ch,chshop,len)strcpy(chshop,"")strncat(chshop,ch,len)gotoxy(,)printf("")}gotoxy(,)printf("s",chshop)ch=getch()}gotoxy(,)j=ch=getch()while(ch!='r'){if(j<){strncat(chmoney,ch,)j}if(ch==){len=strlen(chmoney)strcpy(ch,"")j=jstrncat(ch,chmoney,len)strcpy(chmoney,"")strncat(chmoney,ch,len)gotoxy(,)printf("")}gotoxy(,)printf("s",chmoney)ch=getch()}if((strlen(chshop)==)||(strlen(chmoney)==))continueif((fp=fopen("homedat","a"))!=)fprintf(fp,"sss",chtime,chshop,chmoney)fputc('n',fp)fclose(fp)igotoxy(,i)printf("sss",chtime,chshop,chmoney)}}}==============================================================【程序】题目:计算字符串中子串出现的次数程序分析:程序源代码:#include"stringh"#include"stdioh"main(){charstr,str,*p,*pintsum=printf("pleaseinputtwostringsn")scanf("ss",str,str)p=strp=strwhile(*p!=''){if(*p==*p){while(*p==*p*p!=''){pp}}elsepif(*p=='')sump=str}printf("d",sum)getch()}==============================================================【程序】题目:从键盘输入一些字符逐个把它们送到磁盘上去直到输入一个#为止。程序分析:程序源代码:#include"stdioh"main(){FILE*fpcharch,filenamescanf("s",filename)if((fp=fopen(filename,"w"))==){printf("cannotopenfilen")exit()}ch=getchar()ch=getchar()while(ch!='#'){fputc(ch,fp)putchar(ch)ch=getchar()}fclose(fp)}==============================================================【程序】题目:从键盘输入一个字符串将小写字母全部转换成大写字母然后输出到一个磁盘文件“test”中保存。输入的字符串以~结束。程序分析:程序源代码:#include"stdioh"main(){FILE*fpcharstr,filenameinti=if((fp=fopen("test","w"))==){printf("cannotopenthefilen")exit()}printf("pleaseinputastring:n")gets(str)while(stri!='!'){if(stri>='a'stri<='z')stri=strifputc(stri,fp)i}fclose(fp)fp=fopen("test","r")fgets(str,strlen(str),fp)printf("sn",str)fclose(fp)}==============================================================【程序】题目:有两个磁盘文件A和B,各存放一行字母要求把这两个文件中的信息合并(按字母顺序排列)输出到一个新文件C中。程序分析:程序源代码:#include"stdioh"main(){FILE*fpinti,j,n,nicharc,t,chif((fp=fopen("A","r"))==){printf("fileAcannotbeopenedn")exit()}printf("nAcontentsare:n")for(i=(ch=fgetc(fp))!=EOFi){ci=chputchar(ci)}fclose(fp)ni=iif((fp=fopen("B","r"))==){printf("fileBcannotbeopenedn")exit()}printf("nBcontentsare:n")for(i=(ch=fgetc(fp))!=EOFi){ci=chputchar(ci)}fclose(fp)n=ifor(i=i<ni)for(j=ij<nj)if(ci>cj){t=cici=cjcj=t}printf("nCfileis:n")fp=fopen("C","w")for(i=i<ni){putc(ci,fp)putchar(ci)}fclose(fp)}==============================================================【程序】题目:有五个学生每个学生有门课的成绩从键盘输入以上数据(包括学生号姓名三门课成绩)计算出平均成绩况原有的数据和计算出的平均分数存放在磁盘文件"stud"中。程序分析:程序源代码:#include"stdioh"structstudent{charnumcharnameintscorefloatavr}stumain(){inti,j,sumFILE*fp*input*for(i=i<i){printf("npleaseinputNodscore:n",i)printf("stuNo:")scanf("s",stuinum)printf("name:")scanf("s",stuiname)sum=for(j=j<j){printf("scored",j)scanf("d",stuiscorej)sum=stuiscorej}stuiavr=sum}fp=fopen("stud","w")for(i=i<i)if(fwrite(stui,sizeof(structstudent),,fp)!=)printf("filewriteerrorn")fclose(fp)}经典C语言程序()发表日期:::【程序】题目:*=**其中代表的两位数,*的结果为两位数*的结果为位数。求代表的两位数及*后的结果。程序分析:程序源代码:output(longb,longi){printf("nldld=*ldld",b,i,i,bi)}main(){longinta,b,ia=for(i=i<i){b=i*aif(b>=b<=*i<*i>=)output(b,i)}}==============================================================【程序】题目:八进制转换为十进制程序分析:程序源代码:main(){char*p,sintnp=sgets(p)n=while(*(p)!=''){n=n**p''p}printf("d",n)}==============================================================【程序】题目:求所能组成的奇数个数。程序分析:程序源代码:main(){longsum=,s=intjfor(j=j<=j)*jisplaceofnumber*{printf("nld",sum)if(j<=)s*=elses*=sum=s}printf("nsum=ld",sum)}==============================================================【程序】题目:一个偶数总能表示为两个素数之和。程序分析:程序源代码:#include"stdioh"#include"mathh"main(){inta,b,c,dscanf("d",a)for(b=b<=ab=){for(c=c<=sqrt(b)c)if(bc==)breakif(c>sqrt(b))d=abelsebreakfor(c=c<=sqrt(d)c)if(dc==)breakif(c>sqrt(d))printf("d=ddn",a,b,d)}}==============================================================【程序】题目:判断一个素数能被几个整除程序分析:程序源代码:main(){longintm=,sum=intzi,n=,c=scanf("d",zi)while(n!=){if(!(sumzi))n=else{m=m*sum=summc}}printf("ld,canbedividedbyd""",sum,c)}==============================================================【程序】题目:两个字符串连接程序程序分析:程序源代码:#include"stdioh"main(){chara="acegikm"charb="bdfhjlnpq"charc,*pinti=,j=,k=while(ai!=''bj!=''){if(ai{ck=aii}elseck=bjk}ck=''if(ai=='')p=bjelsep=aistrcat(c,p)puts(c)}==============================================================【程序】题目:回答结果(结构体变量传递)程序分析:程序源代码:#include"stdioh"structstudent{intxcharc}amain(){ax=ac='a'f(a)printf("d,c",ax,ac)}f(structstudentb){bx=bc='y'}==============================================================【程序】题目:读取个数()的整数值每读取一个值程序打印出该值个数的,。程序分析:程序源代码:main(){inti,a,n=while(n<=){do{scanf("d",a)}while(a<||a>)for(i=i<=ai)printf("*")printf("n")n}getch()}==============================================================【程序】题目:某个公司采用公用电话传递数据数据是四位的整数在传递过程中是加密的加密规则如下:每位数字都加上,然后用和除以的余数代替该数字再将第一位和第四位交换第二位和第三位交换。程序分析:程序源代码:main(){inta,i,aa,tscanf("d",a)aa=aaa=aaa=aaa=afor(i=i<=i){aai=aai=}for(i=i<=i){t=aaiaai=aaiaai=t}for(i=i>=i)printf("d",aai)}==============================================================【程序】题目:专升本一题读结果。程序分析:程序源代码:#include"stdioh"#defineMmain(){intaM={,,,,}inti,j,ti=j=Mwhile(i{t=*(ai)*(ai)=*(aj)*(aj)=tij}for(i=iprintf("d",*(ai))

职业精品

用户评论

0/200
    暂无评论

精彩专题

上传我的资料

热门资料

资料评价:

/97
0下载券 下载 加入VIP, 送下载券

意见
反馈

返回
顶部