📄 经典c程序100例==71--80.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0044)file://D:\777\aaa\经典c程序100例==71--80.htm -->
<!-- saved from url=(0041)http://www.vcok.com/class/list.asp?id=210 --><HTML><HEAD><TITLE>经典c程序100例==71--80</TITLE>
<META content="MSHTML 6.00.2600.0" name=GENERATOR>
<META content="铁岭师专beck&杜博 制作 http://www.vcok.com" name=keywords><LINK
href="经典c程序100例==71--80.files/new.css" rel=stylesheet>
<STYLE>.skin0 {
BORDER-RIGHT: black 2px solid; BORDER-TOP: black 2px solid; VISIBILITY: hidden; BORDER-LEFT: black 2px solid; WIDTH: 130px; CURSOR: default; LINE-HEIGHT: 20px; BORDER-BOTTOM: black 2px solid; FONT-FAMILY: Verdana; POSITION: absolute; BACKGROUND-COLOR: menu; TEXT-ALIGN: left
}
.skin1 {
BORDER-RIGHT: buttonhighlight 2px outset; BORDER-TOP: buttonhighlight 2px outset; FONT-SIZE: 9pt; VISIBILITY: hidden; BORDER-LEFT: buttonhighlight 2px outset; WIDTH: 110px; CURSOR: default; BORDER-BOTTOM: buttonhighlight 2px outset; FONT-FAMILY: 宋体, Arial, Helvetica, sans-serif; POSITION: absolute; BACKGROUND-COLOR: menu; TEXT-ALIGN: left
}
.menuitems {
PADDING-RIGHT: 10px; PADDING-LEFT: 15px
}
</STYLE>
<STYLE type=text/css>TD {
FONT-SIZE: 9pt
}
BODY {
FONT-SIZE: 9pt; COLOR: #000000; LINE-HEIGHT: 150%
}
A:link {
COLOR: #000000; TEXT-DECORATION: none
}
A:visited {
COLOR: #000000; TEXT-DECORATION: none
}
A:active {
COLOR: #000000; TEXT-DECORATION: none
}
A:hover {
COLOR: #ff0000; TEXT-DECORATION: underline
}
</STYLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<SCRIPT language=JavaScript>
<!--
var text=">>>> [ w w w . v c o k . c o m ] <<<< "
var speed2=180
var x=0
function s2b()
{var a=text.substring(0,x)
var b=text.substring(x,x+1).toUpperCase()
var c=text.substring(x+1,text.length)
window.status=a+b+c
if(x==text.length){x=0}
else{x++}setTimeout("s2b()",speed2)}
s2b();
//-->
</SCRIPT>
<STYLE type=text/css>A.link-a:hover {
COLOR: #f7f3f7; TEXT-DECORATION: none
}
A.link-a:visited {
COLOR: #ffffff; TEXT-DECORATION: none
}
A.link-a:link {
COLOR: #ffffff; TEXT-DECORATION: none
}
</STYLE>
<META content="Microsoft FrontPage 5.0" name=GENERATOR></HEAD>
<BODY text=#000000 bgColor=#ffffff leftMargin=0
background=经典c程序100例==71--80.files/bg.gif topMargin=0
onload="MM_preloadImages('images/print2.png','images/save2.png','images/re_write2.gif','images/home2.png')">
<P> </P>
<DIV align=center>
<CENTER>
<TABLE id=AutoNumber1 style="BORDER-COLLAPSE: collapse" borderColor=#111111
cellSpacing=0 cellPadding=0 width="80%" border=1>
<TBODY>
<TR>
<TD width="100%">
<P align=left><FONT color=#ff9933><B><FONT color=#3300cc
size=5>经典c程序100例==71--80</FONT></B></FONT></P>
<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<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<3;j++)<BR> {
printf("score
%d.",j+1);<BR> scanf("%d",&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<N;i++)<BR>{
printf("%-6s%-10s",stu[i].num,stu[i].name);<BR> for(j=0;j<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==>\n");<BR>for(i=0;i<=4;i++)<BR>{<BR> scanf("%d",&num);<BR> ptr->data=num;<BR> ptr->next=(link)malloc(sizeof(node));<BR> if(i==4)
ptr->next=NULL;<BR> else
ptr=ptr->next;<BR>}<BR>ptr=head;<BR>while(ptr!=NULL)<BR>{ printf("The
value is
==>%d\n",ptr->data);<BR> ptr=ptr->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->next=NULL;<BR> ptr=tail;<BR> printf("\nplease
input 5
data==>\n");<BR> for(i=0;i<=4;i++)<BR> {<BR> scanf("%d",&num);<BR> ptr->data=num;<BR> head=(link)malloc(sizeof(node));<BR> head->next=ptr;<BR> ptr=head;<BR> }<BR>ptr=ptr->next;<BR>while(ptr!=NULL)<BR>{
printf("The value is
==>%d\n",ptr->data);<BR> ptr=ptr->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->next;<BR>else<BR>{
if(tmp->next->next==NULL)/*delete last
node*/<BR> tmp->next=NULL;<BR> else /*delete the other
node*/<BR> tmp->next=tmp->next->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<num;i++)<BR> {<BR> tmp=pointer;<BR> min=tmp->data;<BR> btmp=NULL;<BR> while(tmp->next)<BR> {
if(min>tmp->next->data)<BR> {min=tmp->next->data;<BR> btmp=tmp;<BR> }<BR> tmp=tmp->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->data=array[0];<BR>tmp1=pointer;<BR>for(i=1;i<num;i++)<BR>{
tmp2=(link)malloc(sizeof(node));<BR> tmp2->next=NULL;<BR> tmp2->data=array[i];<BR> tmp1->next=tmp2;<BR> tmp1=tmp1->next;<BR>}<BR>return
pointer;<BR>}<BR>link concatenate(link pointer1,link pointer2)<BR>{ link
tmp;<BR>tmp=pointer1;<BR>while(tmp->next)<BR> tmp=tmp->next;<BR>tmp->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<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",&n);<BR> if(n>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<=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<=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<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<N;i++)<BR>{if(m<p->age)<BR> q=p++;<BR> m=q->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)>0)
swap(str1,str2);<BR>if(strcmp(str1,str3)>0)
swap(str1,str3);<BR>if(strcmp(str2,str3)>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<10000;i+=4)<BR>{
count=0;<BR>m=i;<BR>for(k=0;k<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>
<P> </P></TD></TR></TBODY></TABLE></CENTER></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -