下载

3下载券

加入VIP
  • 专属下载特权
  • 现金文档折扣购买
  • VIP免费专区
  • 千万文档免费下载

上传资料

关闭

关闭

关闭

封号提示

内容

首页 060118-c-100

060118-c-100.doc

060118-c-100

fjb8142
2018-09-08 0人阅读 举报 0 0 0 暂无简介

简介:本文档为《060118-c-100doc》,可适用于IT/计算机领域

如有错误欢迎讨论!经典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)*             else              bonus=bonus(i)*printf("bonus=d",bonus)}==============================================================【程序】题目:一个整数它加上后是一个完全平方数再加上又是一个完全平方数icsh"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)*i x=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)*k  x=ceil(x*cos(a))  y=ceil(ysin(a)*B)  setcolor()line(x,y,x,y) } for(j=j<=j) {  a=(*PAI)*i(*PAI)*k  x=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=dy x=dxydy if(x<=LEFT||x>=RIGHT) dx=dx if(y<=TOP||y>=BOTTOM)  dy=dy if(x<=LEFT||x>=RIGHT)  dx=dx if(y<=TOP||y>=BOTTOM)  dy=dy if(count>LINES) {  setcolor(color)  color=(color>=MAXCOLOR):color }}closegraph()}【程序】题目:打印出杨辉三角形(要求打印出行如下图)   程序分析:                                                   程序源代码: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("d",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=irads=(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=ifor(j=ijmoveto(pointsix,pointsiy)*Movetobeginningofcord*lineto(pointsjx,pointsjy)*Drawthecord*}}}main(){intdriver,modedriver=CGAmode=CGACinitgraph(driver,mode,"")setcolor()setbkcolor(GREEN)LineToDemo()}==============================================================【程序】题目:输入个数a,b,c按大小顺序输出。   程序分析:利用指针方法。程序源代码:*pointer*main(){intn,n,nint*pointer,*pointer,*pointerprintf("pleaseinputnumber:n,n,n:")scanf("d,d,d",n,n,n)pointer=npointer=npointer=nif(n>n)swap(pointer,pointer)if(n>n)swap(pointer,pointer)if(n>n)swap(pointer,pointer)printf("thesortednumbersare:d,d,dn",n,n,n)}swap(p,p)int*p,*p{intpp=*p*p=*p*p=p}==============================================================【程序】题目:输入数组最大的与第一个元素交换最小的与最后一个元素交换输出数组。程序分析:谭浩强的书中答案有问题。      程序源代码:main(){intnumberinput(number)maxmin(number)output(number)}input(number)intnumber{intifor(i=i<i) scanf("d,",numberi) scanf("d",number)}maxmin(array)intarray{int*max,*min,k,lint*p,*arrendarrend=arraymax=min=arrayfor(p=arrayp<ARRENDP) if(*p>*max)max=p elseif(*p<*min)min=p k=*max l=*min *p=arrayarray=ll=*p *p=arrayarray=kk=*p return}output(array)intarray{int*pfor(p=arrayp<ARRAYP) printf("d,",*p)printf("dn",array)}==============================================================【程序】题目:有n个整数使其前面各数顺序向后移m个位置最后m个数变成最前面的m个数程序分析:程序源代码:main(){intnumber,n,m,iprintf("thetotalnumbersis:")scanf("d",n)printf("backm:")scanf("d",m)for(i=i<NI) scanf("d,",numberi)scanf("d",numbern)move(number,n,m)for(i=i<NI) printf("d,",numberi)printf("d",numbern)}move(array,n,m)intn,m,array{int*p,arrayendarrayend=*(arrayn)for(p=arraynp>arrayp) *p=*(p) *array=arrayend m if(m>)move(array,n,m)}==============================================================【程序】题目:有n个人围成一圈顺序排号。从第一个人开始报数(从到报数)凡报到的人退出   圈子问最后留下的是原来第几号的那位。程序分析:程序源代码:#definenmaxmain(){inti,k,m,n,numnmax,*pprintf("pleaseinputthetotalofnumbers:")scanf("d",n)p=numfor(i=i<NI) *(pi)=i i= k= m= while(m<N) { if(*(pi)!=)k if(k==) {*(pi)= k= m }iif(i==n)i=}while(*p==)pprintf("disleftn",*p)}==============================================================【程序】题目:写一个函数求一个字符串的长度在main函数中输入字符串并输出其长度。   程序分析:程序源代码:main(){intlenchar*strprintf("pleaseinputastring:n")scanf("s",str)len=length(str)printf("thestringhasdcharacters",len)}length(p)char*p{intnn=while(*p!=''){ n p}returnn}【程序】题目:编写input()和output()函数输入输出个学生的数据记录。程序分析:程序源代码:#defineNstructstudent{charnum charname intscore}stuNinput(stu)structstudentstu{inti,j for(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=num ptr>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{intdata structlist*next}typedefstructlistnodetypedefnode*linkvoidmain(){linkptr,head,tail  intnum,i tail=(link)malloc(sizeof(node)) tail>next= ptr=tail printf("npleaseinputdata==>n") for(i=i<=i) {  scanf("d",num)  ptr>data=num  head=(link)malloc(sizeof(node))  head>next=ptr  ptr=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>next returnpointer}}voidselectionsort(linkpointer,intnum){linktmp,btmp inti,min for(i=i<NUMI) { tmp=pointer min=tmp>data btmp= while(tmp>next) {if(min>tmp>next>data) {min=tmp>next>data  btmp=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=arrayi tmp>next=tmp tmp=tmp>next}returnpointer}linkconcatenate(linkpointer,linkpointer){linktmptmp=pointerwhile(tmp>next) tmp=tmp>nexttmp>next=pointerreturnpointer}voidmain(void){intarr={,,,,} linkptr ptr=createlist(arr,) selectionsort(ptr,)}==============================================================【程序】题目:放松一下算一道简单的题目。程序分析:程序源代码:main(){inti,nfor(i=i<i){n= if(i!=) n=n if(i==) n=n if(i==) n=n if(i!=) n=n if(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(mage) q=p m=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=j if(j==)  count else  break} i=m if(count==) {printf("dn",count)  break}}}【程序】题目:*=**其中代表的两位数,*的结果为两位数*的结果为位数。求代表的两位数及*后的结果。程序分析:程序源代码: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=aai aai=aai aai=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))}【程序】题目:时间函数举例程序分析:程序源代码:#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,"ddd",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)

用户评价(0)

关闭

新课改视野下建构高中语文教学实验成果报告(32KB)

抱歉,积分不足下载失败,请稍后再试!

提示

试读已结束,如需要继续阅读或者下载,敬请购买!

评分:

/62

VIP

在线
客服

免费
邮箱

爱问共享资料服务号

扫描关注领取更多福利