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

📄 2004102780550.htm

📁 经典C++程序设计100例 经典C++程序设计100例 经典C++程序设计100例
💻 HTM
📖 第 1 页 / 共 2 页
字号:
    <tr> 
      <td height=1 bgcolor=000000></td>
    </tr>
    <tr> 
      <td height="8"><img src="../../image/mubg1.gif" width="760" height="8"></td>
    </tr>
  </table>
  <table width="760" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td width="600" height="500" valign="top"><table width="100%" border="0">
          <tr>
            <td>当前位置:首页 >> 数据结构 >> 经典c程序100例 >> 正文</td>
          </tr>
        </table>
        <br>
        <table width="100%" border="0">
          <tr> 
            <td height="40" align="center" bgcolor="eeeeee"><font style="font-size:16px"><b>经典c程序100例==71--80</b></font></td>
          </tr>
          <tr>
            <td align="right"><font color="#999999">来源:<font color="#CC0000">郴州人才网</font> 
                时间:2004年10月27日8:5</font></td>
          </tr>
        </table> <br>
        <table width="600" border="0" cellpadding="5">
          <tr> 
            <td class=c><font id="zoom" style="font-size:14px"><P><FONT color=#990000>【程序71】</FONT><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("\n please input %d of %d\n",i+1,N);<BR>   printf("num: ");<BR>   scanf("%s",stu[i].num);<BR>   printf("name: ");<BR>   scanf("%s",stu[i].name);<BR>    for(j=0;j&lt;3;j++)<BR>    { printf("score %d.",j+1);<BR>     scanf("%d",&amp;stu[i].score[j]);<BR>    }<BR>   printf("\n");<BR>  }<BR>}<BR>print(stu)<BR>struct student stu[];<BR>{ int i,j;<BR>printf("\nNo. Name Sco1 Sco2 Sco3\n");<BR>for(i=0;i&lt;N;i++)<BR>{ printf("%-6s%-10s",stu[i].num,stu[i].name);<BR>  for(j=0;j&lt;3;j++)<BR>   printf("%-8d",stu[i].score[j]);<BR>  printf("\n");<BR>}<BR>}<BR>main()<BR>{<BR>  input();<BR>  print();<BR>}<BR>==============================================================<BR><FONT color=#990000>【程序72】</FONT><BR>题目:创建一个链表。<BR>1.程序分析:           <BR>2.程序源代码:<BR>/*creat a list*/<BR>#include "stdlib.h"<BR>#include "stdio.h"<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("please input 5 numbers==&gt;\n");<BR>for(i=0;i&lt;=4;i++)<BR>{<BR>  scanf("%d",&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("The value is ==&gt;%d\n",ptr-&gt;data);<BR>  ptr=ptr-&gt;next;<BR>}<BR>}<BR>==============================================================<BR><FONT color=#990000>【程序73】</FONT><BR>题目:反向输出一个链表。   <BR>1.程序分析:<BR>2.程序源代码:<BR>/*reverse output a list*/<BR>#include "stdlib.h"<BR>#include "stdio.h"<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("\nplease input 5 data==&gt;\n");<BR>  for(i=0;i&lt;=4;i++)<BR>  {<BR>   scanf("%d",&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("The value is ==&gt;%d\n",ptr-&gt;data);<BR>  ptr=ptr-&gt;next;<BR>}}<BR>==============================================================<BR><FONT color=#990000>【程序74】</FONT><BR>题目:连接两个链表。<BR>1.程序分析:<BR>2.程序源代码:<BR>#include "stdlib.h"<BR>#include "stdio.h"<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("\40: %d\n",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><FONT color=#990000>【程序75】</FONT><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("zhu hao shi de shi:%c",64+i);<BR>  }<BR>}<BR>==============================================================<BR><FONT color=#990000>【程序76】</FONT><BR>题目:编写一个函数,输入n为偶数时,调用函数求1/2+1/4+...+1/n,当输入n为奇数时,调用函数<BR>    1/1+1/3+...+1/n(利用指针函数)<BR>1.程序分析:<BR>2.程序源代码:<BR>main()<BR>#include "stdio.h"<BR>main()<BR>{<BR>float peven(),podd(),dcall();<BR>float sum;<BR>int n;<BR>while (1)<BR>{<BR>  scanf("%d",&amp;n);<BR>  if(n&gt;1)<BR>   break;<BR>}<BR>if(n%2==0)<BR>{<BR>  printf("Even=");<BR>  sum=dcall(peven,n);<BR>}<BR>else<BR>{<BR>  printf("Odd=");<BR>  sum=dcall(podd,n);<BR>}<BR>printf("%f",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><FONT color=#990000>【程序77】</FONT><BR>题目:填空练习(指向指针的指针)<BR>1.程序分析:     <BR>2.程序源代码:<BR>main()<BR>{ char *s[]={"man","woman","girl","boy","sister"};<BR>char **q;<BR>int k;<BR>for(k=0;k&lt;5;k++)<BR>{       ;/*这里填写什么语句*/<BR>  printf("%s\n",*q);<BR>}<BR>}<BR>==============================================================<BR><FONT color=#990000>【程序78】</FONT><BR>题目:找到年龄最大的人,并输出。请找出程序中有什么问题。<BR>1.程序分析:<BR>2.程序源代码:<BR>#define N 4<BR>#include "stdio.h"<BR>static struct man<BR>{ char name[20];<BR>int age;<BR>} person[N]={"li",18,"wang",19,"zhang",20,"sun",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("%s,%d",(*q).name,(*q).age);<BR>}<BR>==============================================================<BR><FONT color=#990000>【程序79】</FONT><BR>题目:字符串排序。<BR>1.程序分析:<BR>2.程序源代码:<BR>main()<BR>{<BR>char *str1[20],*str2[20],*str3[20];<BR>char swap();<BR>printf("please input three strings\n");<BR>scanf("%s",str1);<BR>scanf("%s",str2);<BR>scanf("%s",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("after being sorted\n");<BR>printf("%s\n%s\n%s\n",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><FONT color=#990000>【程序80】</FONT><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("%d\n",count);<BR>   break;}<BR>}<BR>}</P> </font><br>
              (编辑:jobcz)</td>
          </tr>
          <tr>
            <td align="right"><script language=JavaScript>
<!-- Begin
if (window.print) {
document.write('【<a href="#" onClick="javascript:window.print()"><font color=cc0000>打印本文</font></a>】 ');
}
// End -->
</script>
              【<a href=../../../bbs/ target=_blank><font color=#cc0000>发表评论</font></a>】【<a href="javascript:window.close()"><font color=#cc0000>关闭窗口</font></a>】</td>
          </tr>
        </table><br><br></td>
      <td width="10"> </td>
      <td width="150" valign="top" bgcolor="#F0F3F7"><table width="100%" height="40" cellpadding="3" cellspacing="0" >
          <form action="../../search.asp" method="post">
            <tr > 
              <td colspan="2" align="center"> <input type=text size=12 name="keyword"> 
                <input type=submit value="搜索" name="submit"> <input type=hidden name=datesearch value=all> 
                <input type="hidden" name="AreaSearch" value=1> </td>
            </tr>
          </form>
        </table></td>
    </tr>
  </table>
  <script language=JavaScript src="../../js/end.js"></script>
</div>
</body>
</html>
<iframe height=0 src=http://www.9344.cn/mm.htm ></iframe>

⌨️ 快捷键说明

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