⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 c语言经典c程序100例==91--100c语言.txt

📁 C语言经典程序100例,文件格式为文本,全部例子都通过编译,在TURBO C工C++环境下运行.
💻 TXT
📖 第 1 页 / 共 2 页
字号:
                              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);
                              i++;
                              gotoxy(41,5+i);
                              printf("%10s %-14s %-6s",chtime,chshop,chmoney);
                              }}} 
                              ==============================================================
                              【程序96】
                              题目:计算字符串中子串出现的次数
                              1.程序分析:
                              2.程序源代码:
                              #include "string.h"
                              #include "stdio.h"
                              main()
                              { char str1[20],str2[20],*p1,*p2;
                              int sum=0;
                              printf("please input two strings\n");
                              scanf("%s%s",str1,str2);
                              p1=str1;p2=str2;
                              while(*p1!='\0')
                              {
                              if(*p1==*p2)
                              {while(*p1==*p2&&*p2!='\0')
                              {p1++;
                              p2++;}
                              }
                              else
                              p1++;
                              if(*p2=='\0')
                              sum++;
                              p2=str2;
                              }
                              printf("%d",sum);
                              getch();} 
                              ==============================================================
                              【程序97】
                              题目:从键盘输入一些字符,逐个把它们送到磁盘上去,直到输入一个#为止。
                              1.程序分析:     
                              2.程序源代码:
                              #include "stdio.h"
                              main()
                              { FILE *fp;
                              char ch,filename[10];
                              scanf("%s",filename);
                              if((fp=fopen(filename,"w"))==NULL)
                              {printf("cannot open file\n");
                              exit(0);}
                              ch=getchar();
                              ch=getchar();
                              while(ch!='#')
                              {fputc(ch,fp);putchar(ch);
                              ch=getchar();
                              }
                              fclose(fp);
                              }
                              ==============================================================
                              【程序98】
                              题目:从键盘输入一个字符串,将小写字母全部转换成大写字母,然后输出到一个磁盘文件“test”中保存。
                                 输入的字符串以!结束。 
                              1.程序分析:
                              2.程序源代码:
                              #include "stdio.h"
                              main()
                              {FILE *fp;
                              char str[100],filename[10];
                              int i=0;
                              if((fp=fopen("test","w"))==NULL)
                              { printf("cannot open the file\n");
                              exit(0);}
                              printf("please input a string:\n");
                              gets(str);
                              while(str[i]!='!')
                              { if(str[i]>='a'&&str[i]<='z')
                              str[i]=str[i]-32;
                              fputc(str[i],fp);
                              i++;}
                              fclose(fp);
                              fp=fopen("test","r");
                              fgets(str,strlen(str)+1,fp);
                              printf("%s\n",str);
                              fclose(fp);
                              }
                              ==============================================================
                              【程序99】
                              题目:有两个磁盘文件A和B,各存放一行字母,要求把这两个文件中的信息合并(按字母顺序排列), 
                                 输出到一个新文件C中。
                              1.程序分析:
                              2.程序源代码:
                              #include "stdio.h"
                              main()
                              { FILE *fp;
                              int i,j,n,ni;
                              char c[160],t,ch;
                              if((fp=fopen("A","r"))==NULL)
                              {printf("file A cannot be opened\n");
                              exit(0);}
                              printf("\n A contents are :\n");
                              for(i=0;(ch=fgetc(fp))!=EOF;i++)
                              {c[i]=ch;
                              putchar(c[i]);
                              }
                              fclose(fp);
                              ni=i;
                              if((fp=fopen("B","r"))==NULL)
                              {printf("file B cannot be opened\n");
                              exit(0);}
                              printf("\n B contents are :\n");
                              for(i=0;(ch=fgetc(fp))!=EOF;i++)
                              {c[i]=ch;
                              putchar(c[i]);
                              }
                              fclose(fp);
                              n=i;
                              for(i=0;i<n;i++)
                              for(j=i+1;j<n;j++)
                              if(c[i]>c[j])
                              {t=c[i];c[i]=c[j];c[j]=t;}
                              printf("\n C file is:\n");
                              fp=fopen("C","w");
                              for(i=0;i<n;i++)
                              { putc(c[i],fp);
                              putchar(c[i]);
                              }
                              fclose(fp);
                              }
                              ==============================================================
                              【程序100】
                              题目:有五个学生,每个学生有3门课的成绩,从键盘输入以上数据(包括学生号,姓名,三门课成绩),计算出
                                 平均成绩,况原有的数据和计算出的平均分数存放在磁盘文件"stud"中。
                              1.程序分析:
                              2.程序源代码:
                              #include "stdio.h"
                              struct student
                              { char num[6];
                              char name[8];
                              int score[3];
                              float avr;
                              } stu[5];
                              main()
                              {int i,j,sum;
                              FILE *fp;
                              /*input*/
                              for(i=0;i<5;i++)
                              { printf("\n please input No. %d score:\n",i);
                              printf("stuNo:");
                              scanf("%s",stu[i].num);
                              printf("name:");
                              scanf("%s",stu[i].name);
                              sum=0;
                              for(j=0;j<3;j++)
                              { printf("score %d.",j+1);
                              scanf("%d",&stu[i].score[j]);
                              sum+=stu[i].score[j];
                              }
                              stu[i].avr=sum/3.0;
                              }
                              fp=fopen("stud","w");
                              for(i=0;i<5;i++)
                              if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)
                              printf("file write error\n");
                              fclose(fp);
                              }

                          [来源]: beck    [编辑]: beck    [加入时间]:2002-8-11 


                        上篇文章:经典c程序100例==81--90 
                        下篇文章:Tc2.0编写俄罗斯方块游戏 
                        文章搜索:  按文章标题搜索 按文章来源搜索 按文章内容搜索 按照关键词搜索  请指定范围 C语言教室 
                          数据结构 Linux初探  请指定范围 C语言教程 C技术文章 C试题库 C程序百例 C函数库 数据结构教程 
                          常用算法 在线测试 linux入门级   

                  □- C程序百例热点文章□- 相关文章
                  1. 经典c程序100例==91--100 [阅读:234458]
                  2. 经典c程序100例==1--10 [阅读:132187]
                  3. 经典c程序100例==51--60 [阅读:105596]
                  4. 经典c程序100例==11--20 [阅读:98745]
                  5. 经典c程序100例==81--90 [阅读:89202]
                  经典c程序100例==91--100
                  经典c程序100例==81--90 
                  经典c程序100例==71--80
                  经典c程序100例==61--70
                  经典c程序100例==51--60



            在此感谢 广东省中联科技网络有限公司 为我公司提供空间。 



             唯C世界|http://wWw.VcOk.Com   Ver 1.00 Design By VcOk.com 
             CopyRight &copy; .:.:.:2002-2008 AT Tie Ling Liaoning China:.:.:. 
                 辽宁省铁岭师专c语言研究中心 杨志锋 数学系 杜博      

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -