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

📄 71.html

📁 经典C语言程序设计100例1-10 如【程序1】 题目:有1、2、3、4个数字
💻 HTML
字号:
<html>
<head>
<title>C程序设计71-80</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" href="cc.css" type="text/css">
</head>

<body bgcolor="#6666FF" text="#FFFFFF" link="#99FF33" alink="#00CC00" vlink="#FFFF00">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="20%">&nbsp;</td>
    <td class="unnamed1"> 
      <div align="center">
        <p align="left"><br>
        </p>
      </div>
      <div align="center"><font color="#FFFF00" size="5">经典c程序100例==71--80 </font></div>
      <p>【程序71】<br>
        题目:编写input()和output()函数输入,输出5个学生的数据记录。<br>
        1.程序分析:<br>
        2.程序源代码:<br>
        #define N 5<br>
        struct student<br>
        { char num[6];<br>
         char name[8];<br>
         int score[4];<br>
        } stu[N];<br>
        input(stu)<br>
        struct student stu[];<br>
        { int i,j;<br>
         for(i=0;i&lt;N;i++)<br>
         { printf(&quot;\n please input %d of %d\n&quot;,i+1,N);<br>
          printf(&quot;num: &quot;);<br>
          scanf(&quot;%s&quot;,stu[i].num);<br>
          printf(&quot;name: &quot;);<br>
          scanf(&quot;%s&quot;,stu[i].name);<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>
           }<br>
          printf(&quot;\n&quot;);<br>
         }<br>
        }<br>
        print(stu)<br>
        struct student stu[];<br>
        { int i,j;<br>
        printf(&quot;\nNo. Name Sco1 Sco2 Sco3\n&quot;);<br>
        for(i=0;i&lt;N;i++)<br>
        { printf(&quot;%-6s%-10s&quot;,stu[i].num,stu[i].name);<br>
         for(j=0;j&lt;3;j++)<br>
          printf(&quot;%-8d&quot;,stu[i].score[j]);<br>
         printf(&quot;\n&quot;);<br>
        }<br>
        }<br>
        main()<br>
        {<br>
         input();<br>
         print();<br>
        }<br>
        ==============================================================<br>
        【程序72】<br>
        题目:创建一个链表。<br>
        1.程序分析:           <br>
        2.程序源代码:<br>
        /*creat a list*/<br>
        #include &quot;stdlib.h&quot;<br>
        #include &quot;stdio.h&quot;<br>
        struct list<br>
        { int data;<br>
        struct list *next;<br>
        };<br>
        typedef struct list node;<br>
        typedef node *link;<br>
        void main()<br>
        { link ptr,head;<br>
        int num,i;<br>
        ptr=(link)malloc(sizeof(node));<br>
        ptr=head;<br>
        printf(&quot;please input 5 numbers==&gt;\n&quot;);<br>
        for(i=0;i&lt;=4;i++)<br>
        {<br>
         scanf(&quot;%d&quot;,&amp;num);<br>
         ptr-&gt;data=num;<br>
         ptr-&gt;next=(link)malloc(sizeof(node));<br>
         if(i==4) ptr-&gt;next=NULL;<br>
         else ptr=ptr-&gt;next;<br>
        }<br>
        ptr=head;<br>
        while(ptr!=NULL)<br>
        { printf(&quot;The value is ==&gt;%d\n&quot;,ptr-&gt;data);<br>
         ptr=ptr-&gt;next;<br>
        }<br>
        }<br>
        ==============================================================<br>
        【程序73】<br>
        题目:反向输出一个链表。   <br>
        1.程序分析:<br>
        2.程序源代码:<br>
        /*reverse output a list*/<br>
        #include &quot;stdlib.h&quot;<br>
        #include &quot;stdio.h&quot;<br>
        struct list<br>
        { int data;<br>
         struct list *next;<br>
        };<br>
        typedef struct list node;<br>
        typedef node *link;<br>
        void main()<br>
        { link ptr,head,tail; <br>
         int num,i;<br>
         tail=(link)malloc(sizeof(node));<br>
         tail-&gt;next=NULL;<br>
         ptr=tail;<br>
         printf(&quot;\nplease input 5 data==&gt;\n&quot;);<br>
         for(i=0;i&lt;=4;i++)<br>
         {<br>
          scanf(&quot;%d&quot;,&amp;num);<br>
          ptr-&gt;data=num;<br>
          head=(link)malloc(sizeof(node));<br>
          head-&gt;next=ptr;<br>
          ptr=head;<br>
         }<br>
        ptr=ptr-&gt;next;<br>
        while(ptr!=NULL)<br>
        { printf(&quot;The value is ==&gt;%d\n&quot;,ptr-&gt;data);<br>
         ptr=ptr-&gt;next;<br>
        }}<br>
        ==============================================================<br>
        【程序74】<br>
        题目:连接两个链表。<br>
        1.程序分析:<br>
        2.程序源代码:<br>
        #include &quot;stdlib.h&quot;<br>
        #include &quot;stdio.h&quot;<br>
        struct list<br>
        { int data;<br>
        struct list *next;<br>
        };<br>
        typedef struct list node;<br>
        typedef node *link;<br>
        link delete_node(link pointer,link tmp)<br>
        {if (tmp==NULL) /*delete first node*/<br>
         return pointer-&gt;next;<br>
        else<br>
        { if(tmp-&gt;next-&gt;next==NULL)/*delete last node*/<br>
          tmp-&gt;next=NULL;<br>
         else /*delete the other node*/<br>
          tmp-&gt;next=tmp-&gt;next-&gt;next;<br>
         return pointer;<br>
        }<br>
        }<br>
        void selection_sort(link pointer,int num)<br>
        { link tmp,btmp;<br>
         int i,min;<br>
         for(i=0;i&lt;num;i++)<br>
         {<br>
         tmp=pointer;<br>
         min=tmp-&gt;data;<br>
         btmp=NULL;<br>
         while(tmp-&gt;next)<br>
         { if(min&gt;tmp-&gt;next-&gt;data)<br>
         {min=tmp-&gt;next-&gt;data;<br>
          btmp=tmp;<br>
         }<br>
         tmp=tmp-&gt;next;<br>
         }<br>
        printf(&quot;\40: %d\n&quot;,min);<br>
        pointer=delete_node(pointer,btmp);<br>
        }<br>
        }<br>
        link create_list(int array[],int num)<br>
        { link tmp1,tmp2,pointer;<br>
        int i;<br>
        pointer=(link)malloc(sizeof(node));<br>
        pointer-&gt;data=array[0];<br>
        tmp1=pointer;<br>
        for(i=1;i&lt;num;i++)<br>
        { tmp2=(link)malloc(sizeof(node));<br>
         tmp2-&gt;next=NULL;<br>
         tmp2-&gt;data=array[i];<br>
         tmp1-&gt;next=tmp2;<br>
         tmp1=tmp1-&gt;next;<br>
        }<br>
        return pointer;<br>
        }<br>
        link concatenate(link pointer1,link pointer2)<br>
        { link tmp;<br>
        tmp=pointer1;<br>
        while(tmp-&gt;next)<br>
         tmp=tmp-&gt;next;<br>
        tmp-&gt;next=pointer2;<br>
        return pointer1;<br>
        }<br>
        void main(void)<br>
        { int arr1[]={3,12,8,9,11};<br>
         link ptr;<br>
         ptr=create_list(arr1,5);<br>
         selection_sort(ptr,5);<br>
        }<br>
        ==============================================================<br>
        【程序75】<br>
        题目:放松一下,算一道简单的题目。<br>
        1.程序分析:<br>
        2.程序源代码:<br>
        main()<br>
        {<br>
        int i,n;<br>
        for(i=1;i&lt;5;i++)<br>
        { n=0;<br>
         if(i!=1)<br>
         n=n+1;<br>
         if(i==3)<br>
         n=n+1;<br>
         if(i==4)<br>
         n=n+1;<br>
         if(i!=4)<br>
         n=n+1;<br>
         if(n==3)<br>
          printf(&quot;zhu hao shi de shi:%c&quot;,64+i);<br>
         }<br>
        }<br>
        ==============================================================<br>
        【程序76】<br>
        题目:编写一个函数,输入n为偶数时,调用函数求1/2+1/4+...+1/n,当输入n为奇数时,调用函数<br>
           1/1+1/3+...+1/n(利用指针函数)<br>
        1.程序分析:<br>
        2.程序源代码:<br>
        main()<br>
        #include &quot;stdio.h&quot;<br>
        main()<br>
        {<br>
        float peven(),podd(),dcall();<br>
        float sum;<br>
        int n;<br>
        while (1)<br>
        {<br>
         scanf(&quot;%d&quot;,&amp;n);<br>
         if(n&gt;1)<br>
          break;<br>
        }<br>
        if(n%2==0)<br>
        {<br>
         printf(&quot;Even=&quot;);<br>
         sum=dcall(peven,n);<br>
        }<br>
        else<br>
        {<br>
         printf(&quot;Odd=&quot;);<br>
         sum=dcall(podd,n);<br>
        }<br>
        printf(&quot;%f&quot;,sum);<br>
        }<br>
        float peven(int n)<br>
        {<br>
        float s;<br>
        int i;<br>
        s=1;<br>
        for(i=2;i&lt;=n;i+=2)<br>
         s+=1/(float)i;<br>
        return(s);<br>
        }<br>
        float podd(n)<br>
        int n;<br>
        {<br>
        float s;<br>
        int i;<br>
        s=0;<br>
        for(i=1;i&lt;=n;i+=2)<br>
         s+=1/(float)i;<br>
        return(s);<br>
        }<br>
        float dcall(fp,n)<br>
        float (*fp)();<br>
        int n;<br>
        {<br>
        float s;<br>
        s=(*fp)(n);<br>
        return(s);<br>
        }<br>
        ==============================================================<br>
        【程序77】<br>
        题目:填空练习(指向指针的指针)<br>
        1.程序分析:     <br>
        2.程序源代码:<br>
        main()<br>
        { char *s[]={&quot;man&quot;,&quot;woman&quot;,&quot;girl&quot;,&quot;boy&quot;,&quot;sister&quot;};<br>
        char **q;<br>
        int k;<br>
        for(k=0;k&lt;5;k++)<br>
        {       ;/*这里填写什么语句*/<br>
         printf(&quot;%s\n&quot;,*q);<br>
        }<br>
        }<br>
        ==============================================================<br>
        【程序78】<br>
        题目:找到年龄最大的人,并输出。请找出程序中有什么问题。<br>
        1.程序分析:<br>
        2.程序源代码:<br>
        #define N 4<br>
        #include &quot;stdio.h&quot;<br>
        static struct man<br>
        { char name[20];<br>
        int age;<br>
        } person[N]={&quot;li&quot;,18,&quot;wang&quot;,19,&quot;zhang&quot;,20,&quot;sun&quot;,22};<br>
        main()<br>
        {struct man *q,*p;<br>
        int i,m=0;<br>
        p=person;<br>
        for (i=0;i&lt;N;i++)<br>
        {if(m&lt;p-&gt;age)<br>
         q=p++;<br>
         m=q-&gt;age;}<br>
        printf(&quot;%s,%d&quot;,(*q).name,(*q).age);<br>
        }<br>
        ==============================================================<br>
        【程序79】<br>
        题目:字符串排序。<br>
        1.程序分析:<br>
        2.程序源代码:<br>
        main()<br>
        {<br>
        char *str1[20],*str2[20],*str3[20];<br>
        char swap();<br>
        printf(&quot;please input three strings\n&quot;);<br>
        scanf(&quot;%s&quot;,str1);<br>
        scanf(&quot;%s&quot;,str2);<br>
        scanf(&quot;%s&quot;,str3);<br>
        if(strcmp(str1,str2)&gt;0) swap(str1,str2);<br>
        if(strcmp(str1,str3)&gt;0) swap(str1,str3);<br>
        if(strcmp(str2,str3)&gt;0) swap(str2,str3);<br>
        printf(&quot;after being sorted\n&quot;);<br>
        printf(&quot;%s\n%s\n%s\n&quot;,str1,str2,str3);<br>
        }<br>
        char swap(p1,p2)<br>
        char *p1,*p2;<br>
        {<br>
        char *p[20];<br>
        strcpy(p,p1);strcpy(p1,p2);strcpy(p2,p);<br>
        }<br>
        ==============================================================<br>
        【程序80】<br>
        题目:海滩上有一堆桃子,五只猴子来分。第一只猴子把这堆桃子凭据分为五份,多了一个,这只<br>
           猴子把多的一个扔入海中,拿走了一份。第二只猴子把剩下的桃子又平均分成五份,又多了<br>
           一个,它同样把多的一个扔入海中,拿走了一份,第三、第四、第五只猴子都是这样做的,<br>
           问海滩上原来最少有多少个桃子?<br>
        1.程序分析:<br>
        2.程序源代码:<br>
        main()<br>
        {int i,m,j,k,count;<br>
        for(i=4;i&lt;10000;i+=4)<br>
        { count=0;<br>
        m=i;<br>
        for(k=0;k&lt;5;k++)<br>
        {<br>
         j=i/4*5+1;<br>
         i=j;<br>
         if(j%4==0)<br>
          count++;<br>
         else<br>
          break;<br>
        }<br>
         i=m;<br>
         if(count==4)<br>
         {printf(&quot;%d\n&quot;,count);<br>
          break;}<br>
        }<br>
        }<br>
      </p>
      <br>
    </td>
    <td width="20%">&nbsp;</td>
  </tr>
</table>
</body>
</html>

⌨️ 快捷键说明

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