版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
==============================================================题目:海滩上有一堆桃子,五只猴子来分。第一只猴子把这堆桃子凭据分为五份,多只猴子把多的一个扔入海中,拿走了一份。第二只猴子把剩下的桃子又平均分成五份,又多了一个,它同样把多的一个扔入海中,拿走了一份,第三、第四、第五只猴子都{inti,m,j,k,count;for(i=4;i<10000;i+=4){count=0;for(k=0;k<5;k++){j=i/4*5+1;if(j%4==0)count++;ek}if(count==4){printf("%d\n",count);eak}}作者:zhlei812005-1-2211:32回复此发言--------------------------------------------------------------------------------16回复:经典C源程序100例output(longb,longi){printf("\n%ld/%ld=809*%ld+%ld",b,i,i,b%i);}{longinta,b,i;a=809;for(i=10;i<100;i++){b=i*a+1;if(b>=1000&&b<=10000&&8*i<100&&9*i>=100)output(b,i);}}==============================================================题目:八进制转换为十进制{char*p,s[6];intn;gets(p);while(*(p)!='\0'){n=n*8+*p-'0';printf("%d",n);}=============================================================={longsum=4,s=4;for(j=2;j<=8;j++)/*jisplaceofnumber*/{printf("\n%ld",sum);ifjs*=7;lses*=8;sum+=s;}printf("\nsum=%ld",sum);}==============================================================题目:一个偶数总能表示为两个素数之和。#include"stdio.h"#include"math.h"{inta,b,c,d;scanf("%d",&a);for(b=3;b<=a/2;b+=2){for(c=2;c<=sqrt(b);c++)if(b%c==0)break;if(c>sqrt(b))d=a-b;lseeakfor(c=2;c<=sqrt(d);c++)if(d%c==0)break;if(c>sqrt(d))printf("%d=%d+%d\n",a,b,d);}}==============================================================几个9整除{longintm9=9,sum=9;intzi,n1=1,c9=1;scanf("%d",&zi);while(n1!=0){if(!(sum%zi))lse{m9=m9*10;sum=sum+m9;c9++;}}printf("%ld,canbedividedby%d\"9\"",sum,c9);}==============================================================题目:两个字符串连接程序#include"stdio.h"{chara[]="acegikm";charb[]="bdfhjlnpq";charc[80],*p;inti=0,j=0,k=0;while(a[i]!='\0'&&b[j]!='\0'){if(a[i]{c[k]=a[i];i++;}lsec[k]=b[j++];}c[k]='\0';if(a[i]=='\0')pbjlsepaistrcat(c,p);puts©;}==============================================================题目:回答结果(结构体变量传递)#include"stdio.h"structstudentintx;charc;}a;{a.x=3;a.c='a';f(a);printf("%d,%c",a.x,a.c);}f(structstudentb){bx20;bc'y';}==============================================================题目:读取7个数(1—50)的整数值,每读取一个值,程序打印出该值个数的*。{inti,a,n=1;while(n<=7){do{scanf("%d",&a);}while(a<1¦¦a>50);for(i=1;i<=a;i++)printf("*");printf("\n");getch();}==============================================================题目:某个公司采用公用电话传递数据,数据是四位的整数,在传递过程中是加密的,换,第二位和第三位交换。{inta,i,aa[4],t;scanf("%d",&a);aa[0]=a%10;aa[1]=a%100/10;aa[2]=a%1000/100;aa[3]=a/1000;for(i=0;i<=3;i++){aa[i]+=5;aa[i]%=10;}for(i=0;i<=3/2;i++){t=aa[i];aa[i]=aa[3-i];aa[3-i]=t;}for(i=3;i>=0;i--)printf("%d",aa[i]);}==============================================================题目:专升本一题,读结果。#include"stdio.h"#defineM5{inta[M]={1,2,3,4,5};intijti=0;j=M-1;while(i{t=*(a+i);*(a+i)=*(a+j);*(a+j)=t;i++;j--;}for(i=0;iprintf("%d",*(a+i));}作者:zhlei812005-1-2211:33回复此发言--------------------------------------------------------------------------------17回复:经典C源程序100例举例1#include"stdio.h"#include"time.h"voidmain(){time_tlt;/*definealonginttimevarible*/lt=time(NULL);/*systemtimeanddate*/printf(ctime(<));/*englishformatoutput*/printf(asctime(localtime(<)));/*tranfertotm*/printf(asctime(gmtime(<)));/*tranfertoGreenwichtime*/}==============================================================/*calculatetime*/#include"time.h"#include"stdio.h"{time_tstart,end;ntistart=time(NULL);for(i=0;i<3000;i++){printf("\1\1\1\1\1\1\1\1\1\1\n");}end=time(NULL);printf("\1:Thedifferentis%6.3f\n",difftime(end,start));}==============================================================/*calculatetime*/#include"time.h"#include"stdio.h"{clock_tstart,end;ntidoublevar;start=clock();for(i=0;i<10000;i++){printf("\1\1\1\1\1\1\1\1\1\1\n");}end=clock();printf("\1:Thedifferentis%6.3f\n",(double)(end-start));}==============================================================题目:时间函数举例4,一个猜数游戏,判断一个人反应快慢。(版主初学时编的)#include"time.h"#include"stdlib.h"#include"stdio.h"{charc;clock_tstart,end;time_ta,b;doublevar;inti,guess;srand(time(NULL));printf("doyouwanttoplayit.('y'or'n')\n");while((c=getchar())=='y'){i=rand()%100;printf("\npleaseinputnumberyouguess:\n");start=clock();a=time(NULL);scanf("%d",&guess);while(guess!=i){if(guess>i){printf("pleaseinputalittlesmaller.\n");scanf("%d",&guess);}lse{printf("pleaseinputalittlebigger.\n");scanf("%d",&guess);}}end=clock();b=time(NULL);printf("\1:Ittookyou%6.3fseconds\n",var=(double)(end-start)/18.2);printf("\1:ittookyou%6.3fseconds\n\n",difftime(b,a));if(var<15)printf("\1\1Youareveryclever!\1\1\n\n");elseif(var<25)printf("\1\1youarenormal!\1\1\n\n");lseprintf("\1\1youarestupid!\1\1\n\n");printf("\1\1Congradulations\1\1\n\n");printf("Thenumberyouguessis%d",i);}printf("\ndoyouwanttotryitagain?(\"yy\".or.\"n\")\n");if((c=getch())=='y')gotoloop;}==============================================================题目:家庭财务管理小程序/*moneymanagementsystem*/#include"stdio.h"#include"dos.h"{structdated;floatsum,chm=0.0;intlen,i,j=0;charch[4]="",ch1[16]="",chtime[12]="",chshop[16],chmoney[8];pp:clrscr();sum=0.0;gotoxy(1,1);printf("¦---------------------------------------------------------------------------¦");gotoxy(1,2);printf("¦moneymanagementsystem(C1.0)2000.03¦");gotoxy(1,3);printf("¦---------------------------------------------------------------------------¦");gotoxy(1,4);printf("¦--moneyrecords--¦--todaycostlist--¦");作者:zhlei812005-1-2211:33回复此发言--------------------------------------------------------------------------------18回复:经典C源程序100例gotoxy(1,5);printf("¦------------------------¦-------------------------------------¦");gotoxy(1,6);printf("¦date:--------------¦¦");gotoxy(1,7);printf("¦¦¦¦¦");gotoxy(1,8);printf("¦--------------¦¦");gotoxy(1,9);printf("¦thgs:------------------¦¦");gotoxy(1,10);printf("¦¦¦¦¦");gotoxy(1,11);printf("¦------------------¦¦");gotoxy(1,12);printf("¦cost:----------¦¦");gotoxy(1,13);printf("¦¦¦¦¦");gotoxy(1,14);printf("¦----------¦¦");gotoxy(1,15);printf("¦¦¦");gotoxy(1,16);printf("¦¦¦");gotoxy(1,17);printf("¦¦¦");gotoxy(1,18);printf("¦¦¦");gotoxy(1,19);printf("¦¦¦");gotoxy(1,20);printf("¦¦¦");gotoxy(1,21);printf("¦¦¦");gotoxy(1,22);printf("¦¦¦");gotoxy(1,23);printf("¦---------------------------------------------------------------------------¦");getdate(&d);sprintf(chtime,"%4d.%02d.%02d",d.da_year,d.da_mon,d.da_day);lsefor(;;){gotoxy(3,24);printf("Tab__browsecostlistEsc__quit");gotoxy(13,10);printf("");gotoxy(13,13);printf("");gotoxy(13,7);printf("%s",chtime);j=18;ch[0]=getch();if(ch[0]==27)eakstrcpy(chshop,"");strcpy(chmoney,"");if(ch[0]==9){mmi0;fp=fopen("home.dat","r+");gotoxy(3,24);printf("");gotoxy(6,4);printf("listrecords");gotoxy(1,5);printf("¦-------------------------------------¦");gotoxy(41,4);printf("");gotoxy(41,5);printf("¦");while(fscanf(fp,"%10s%14s%f\n",chtime,chshop,&chm)!=EOF){if(i==36){getch();if((i%36)<17){gotoxy(4,6+i);printf("");gotoxy(4,6+i);}if((i%36)>16){gotoxy(41,4+i-17);printf("");gotoxy(42,4+i-17);}sum=sum+chm;printf("%10s%-14s%6.1f\n",chtime,chshop,chm);}gotoxy(1,23);printf("¦---------------------------------------------------------------------------¦");gotoxy(1,24);printf("¦¦");gotoxy(1,25);printf("¦---------------------------------------------------------------------------¦");gotoxy(10,24);printf("totalis%8.1f$",sum);fclose(fp);gotoxy(49,24);printf("pressanykeyto.....");getch();gotopp;}lse{while(ch[0]!='\r'){if(j<10){strncat(chtime,ch,1);j++;}if(ch[0]==8){len=strlen(chtime)-1;ifj){len=len+1;j=11;}strcpy(ch1,"");j=j-2;strncat(ch1,chtime,len);strcpy(chtime,"");strncat(chtime,ch1,len-1);gotoxy(13,7);printf("");}gotoxy(13,7);printf("%s",chtime);ch[0]=getch();if(ch[0]==9)gotomm;if(ch[0]==27)exit(1);}gotoxy(3,24);printf("");gotoxy(13,10);j=0;ch[0]=getch();while(ch[0]!='\r'){if(j<14){strncat(chshop,ch,1);j++;}if(ch[0]==8){len=strlen(chshop)-1;strcpy(ch1,"");j=j-2;strncat(ch1,chshop,len);strcpy(chshop,"");strncat(chshop,ch1,len-1);gotoxy(13,10);printf("");}gotoxy(13,10);printf("%s",chshop);ch[0]=getch();}gotoxy(13,13);j=0;ch[0]=getch();while(ch[0]!='\r'){if(j<6){strncat(chmoney,ch,1);j++;}if(ch[0]==8){len=strlen(chmoney)-1;strcpy(ch1,"");j=j-2;strncat(ch1,chmoney,len);strcpy(chmoney,"");strncat(chmoney,ch1,len-1);gotoxy(13,13);printf("");}gotoxy(13,13);printf("%s",chmoney);ch[0]=getch();}if((strlen(chshop)==0)¦¦(strlen(chmoney)==0))continue;if((fp=fopen("home.dat","a+"))!=NULL);fprintf(fp,"%10s%14s%6s",chtime,chshop,chmoney);fputc('\n',fp);fclose(fp);gotoxy(41,5+i);printf("%10s%-14s%-6s",chtime,chshop,chmoney);==============================================================题目:计算字符串中子串出现的次数#include"string.h"#include"stdio.h"{charstr1[20],str2[20],*p1,*p2;intsum=0;printf("pleaseinputtwostrings\n");scanf("%s%s",str1,str2);p1=str1;p2=str2;while(*p1!='\0'){if(*p1==*p2){while(*p1==*p2&&*p2!='\0'){p1++;p+;}}lsep;if(*p2=='\0')sum++;p2=str2;}printf("%d",sum);getch();}==============================================================题目:从键盘输入一些字符,逐个把它们送到磁盘上去,直到输入一个#为止。#include"stdio.h"{FILE*fp;charch,filename[10];scanf("%s",filename);if((fp=fopen(filename,"w"))==NULL){printf("cannotopenfile\n");exit(0);}ch=getchar();ch=getchar();while(ch!='#'){fputc(ch,fp);putchar(ch);ch=getchar();}fclose(fp);}==============================================================题目:从键盘输入一个字符串,将小写字母全部转换成大写字母,然后输出到一个磁test”中保存。输入的字符串以!结束。#include"stdio.h"{FILE*fp;charstr[100],filename[10];intiif((fp=fopen("test","w"))==NULL){printf("cannotopenthefile\n");exit(0);}printf("pleaseinputastring:\n");gets(str);while(str!='!'){if(str>='a'&&str<='z')str=str-32;fputc(str,fp);fclose(fp);fp=fopen("test","r");fgets(str,strlen(str)+1,fp);printf("%s\n",str);fclose(fp);}作者:zhlei812005-1-2211:33回复此发言--------------------------------------------------------------------------------19回复:经典C源程序100例题目:有两个磁盘文件A和B,各存放一行字母,要求把这两个文件中的信息合并(按字母顺序排列),程序分析:2.程序源代码:#include"stdio.h"{FILE*fp;inti,j,n,ni;charc[160],t,c
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 甘肃省庆阳市一级建造师考试(机电工程管理与实务)题库含答案(2025年)
- 2026年国家法律职业资格考试大纲及试题
- 2026年资产评估师考试历年真题汇编
- 2025年无人机飞手:作业成本核算与服务定价策略
- 2026年浙江丽水国家粮食储备库招录仓库管理员100人易考易错模拟试题(共500题)试卷后附参考答案
- 2026年泸州市泸县政府投资建设工程管理中心招考事业单位人员易考易错模拟试题(共500题)试卷后附参考答案
- 2026年河南郑州新密市巡察工作数据中心招聘易考易错模拟试题(共500题)试卷后附参考答案
- 2026年河南省沁阳市事业单位招考易考易错模拟试题(共500题)试卷后附参考答案
- 2026年河南洛阳老城区招考事业单位25人易考易错模拟试题(共500题)试卷后附参考答案
- 2026年河南信阳市光山县事业单位招考易考易错模拟试题(共500题)试卷后附参考答案
- 2026厦门国有资本运营有限责任公司招聘笔试历年常考点试题专练附带答案详解
- 2026山东威海热电集团有限公司招聘44人笔试参考题库及答案解析
- 儿童夏日防暑安全知识课堂
- 2026年陕西好猫卷烟材料有限责任公司招聘(10人)笔试模拟试题及答案解析
- 临床老年人腹泻“防”与“护”
- 甲状腺疾病的预防与护理
- 雨课堂学堂云在线《人工智能原理》单元测试考核答案
- 【MOOC】《知识创新与学术规范》(南京大学)期末考试慕课答案
- 国开《学位论文指南》形考作业1-2答案
- DL-T 1476-2023 电力安全工器具预防性试验规程
- GA 61-2010固定灭火系统驱动、控制装置通用技术条件
评论
0/150
提交评论