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

📄 91.html

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

⌨️ 快捷键说明

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