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

📄 c语言经典程序100例.htm

📁 文件包含100个经典C语言程序文件
💻 HTM
📖 第 1 页 / 共 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>{<BR>printf("The 
value is 
==&gt;%d\n",ptr-&gt;data);<BR>ptr=ptr-&gt;next;<BR>}<BR>getch();<BR>}<BR>==============================================================<BR>【程序73】<BR>题目:反向输出一个链表。   <BR>1.程序分析:<BR>2.程序源代码:<BR>/*reverse 
output a list*/<BR>#include "stdlib.h"<BR>#include "stdio.h"<BR>#include 
"conio.h"<BR>struct list<BR>{<BR>int data;<BR>struct list 
*next;<BR>};<BR>typedef struct list node;<BR>typedef node *link;<BR>void 
main()<BR>{<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>{<BR>printf("The 
value is 
==&gt;%d\n",ptr-&gt;data);<BR>ptr=ptr-&gt;next;<BR>}<BR>getch();<BR>}<BR>==============================================================<BR>【程序74】<BR>题目:连接两个链表。<BR>1.程序分析:<BR>2.程序源代码:<BR>#include 
"stdlib.h"<BR>#include "stdio.h"<BR>#include "conio.h"<BR>struct 
list<BR>{<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>{<BR>if (tmp==NULL) /*delete first node*/<BR>return 
pointer-&gt;next;<BR>else<BR>{<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>{<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>{<BR>if(min&gt;tmp-&gt;next-&gt;data)<BR>{<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>{<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>{<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>{<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>{<BR>int arr1[]={3,12,8,9,11};<BR>link 
ptr;<BR>ptr=create_list(arr1,5);<BR>selection_sort(ptr,5);<BR>getch();<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>{<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>getch();<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>#include 
"stdio.h"<BR>#include "conio.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>getch();<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>#include 
"stdio.h"<BR>#include "conio.h"<BR>main()<BR>{<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>getch();<BR>}<BR>==============================================================<BR>【程序78】<BR>题目:找到年龄最大的人,并输出。请找出程序中有什么问题。<BR>1.程序分析:<BR>2.程序源代码:<BR>#define 
N 4<BR>#include "stdio.h"<BR>#include "conio.h"<BR>static struct 
man<BR>{<BR>char name[20];<BR>int 
age;<BR>}person[N]={"li",18,"wang",19,"zhang",20,"sun",22};<BR>main()<BR>{<BR>struct 
man *q,*p;<BR>int i,m=0;<BR>p=person;<BR>for 
(i=0;i&lt;N;i++)<BR>{<BR>if(m&lt;p-&gt;age)<BR>q=p++;<BR>m=q-&gt;age;<BR>}<BR>printf("%s,%d",(*q).name,(*q).age);<BR>getch();<BR>}<BR>==============================================================<BR>【程序79】<BR>题目:字符串排序。<BR>1.程序分析:<BR>2.程序源代码:<BR>#include 
"stdio.h"<BR>#include "conio.h"<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>getch();<BR>}<BR>char 
swap(p1,p2)<BR>char *p1,*p2;<BR>{<BR>char 
*p[20];<BR>strcpy(p,p1);<BR>strcpy(p1,p2);<BR>strcpy(p2,p);<BR>}<BR>==============================================================<BR>【程序80】<BR>题目:海滩上有一堆桃子,五只猴子来分。第一只猴子把这堆桃子凭据分为五份,多了一个,这只 
<BR>   猴子把多的一个扔入海中,拿走了一份。第二只猴子把剩下的桃子又平均分成五份,又多了<BR>   一个,它同样把多的一个扔入海中,拿走了一份,第三、第四、第五只猴子都是这样做的,<BR>   问海滩上原来最少有多少个桃子?<BR>1.程序分析:<BR>2.程序源代码:<BR>#include 
"stdio.h"<BR>#include "conio.h"<BR>main()<BR>{<BR>int 
i,m,j,k,count;<BR>for(i=4;i&lt;10000;i+=4)<BR>{<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>{<BR>printf("%d\n",count);<BR>break;<BR>}<BR>}<BR>getch();<BR>}</P>
<P>  .:.:经典c程序100例==81--90:.:. 
<BR>    经典c程序100例==81--90<BR>【程序81】<BR>题目:809*??=800*??+9*??+1 
其中??代表的两位数,8*??的结果为两位数,9*??的结果为3位数。求??代表的两位数,及809*??后的结果。<BR>1.程序分析:<BR>2.程序源代码:<BR>#include 
"stdio.h"<BR>#include "conio.h"<BR>output(long b,long 
i)<BR>{<BR>printf("\n%ld/%ld=809*%ld+%ld",b,i,i,b%i);<BR>}<BR>main()<BR>{<BR>long 
int 
a,b,i;<BR>a=809;<BR>for(i=10;i&lt;100;i++)<BR>{<BR>b=i*a+1;<BR>if(b&gt;=1000&amp;&amp;b&lt;=10000&amp;&amp;8*i&lt;100&amp;&amp;9*i&gt;=100)<BR>output(b,i);<BR>}<BR>getch();<BR>}<BR>==============================================================<BR>【程序82】<BR>题目:八进制转换为十进制<BR>1.程序分析:           <BR>2.程序源代码:<BR>#include 
"stdio.h"<BR>#include "conio.h"<BR>main()<BR>{<BR>char *p,s[6];int 
n;<BR>p=s;<BR>gets(p);<BR>n=0;<BR>while(*(p)!='\0')<BR>{<BR>n=n*8+*p-'0';<BR>p++;<BR>}<BR>printf("%d",n);<BR>getch();<BR>}<BR>==============================================================<BR>【程序83】<BR>题目:求0-7所能组成的奇数个数。<BR>1.程序分析:<BR>2.程序源代码:<BR>#include 
"stdio.h"<BR>#include "conio.h"<BR>main()<BR>{<BR>long sum=4,s=4;<BR>int 
j;<BR>for(j=2;j&lt;=8;j++)/*j is place of 
number*/<BR>{<BR>printf("\n%ld",sum);<BR>if(j&lt;=2)<BR>s*=7;<BR>else<BR>s*=8;<BR>sum+=s;<BR>}<BR>printf("\nsum=%ld",sum);<BR>getch();<BR>}<BR>==============================================================<BR>【程序84】<BR>题目:一个偶数总能表示为两个素数之和。<BR>1.程序分析:<BR>2.程序源代码:<BR>#include 
"stdio.h"<BR>#include "conio.h"<BR>#include "math.h"<BR>main()<BR>{<BR>int 
a,b,c,d;<BR>scanf("%d",&amp;a);<BR>for(b=3;b&lt;=a/2;b+=2)<BR>{<BR>for(c=2;c&lt;=sqrt(b);c++)<BR>if(b%c==0) 
break;<BR>if(c&gt;sqrt(b))<BR>d=a-b;<BR>else<BR>break;<BR>for(c=2;c&lt;=sqrt(d);c++)<BR>if(d%c==0) 
break;<BR>if(c&gt;sqrt(d))<BR>printf("%d=%d+%d\n",a,b,d);<BR>}<BR>getch();<BR>}<BR>==============================================================<BR>【程序85】<BR>题目:判断一个素数能被几个9整除<BR>1.程序分析:<BR>2.程序源代码:<BR>#include 
"stdio.h"<BR>#include "conio.h"<BR>main()<BR>{<BR>long int m9=9,sum=9;<BR>int 
zi,n1=1,c9=1;<BR>scanf("%d",&amp;zi);<BR>while(n1!=0)<BR>{<BR>if(!(sum%zi))<BR>n1=0;<BR>else<BR>{<BR>m9=m9*10;<BR>sum=sum+m9;<BR>c9++;<BR>}<BR>}<BR>printf("%ld,can 
be divided by %d 
\"9\"",sum,c9);<BR>getch();<BR>}<BR>==============================================================<BR>【程序86】<BR>题目:两个字符串连接程序<BR>1.程序分析:<BR>2.程序源代码:<BR>#include 
"stdio.h"<BR>#include "conio.h"<BR>main()<BR>{<BR>char a[]="acegikm";<BR>char 
b[]="bdfhjlnpq";<BR>char c[80],*p;<BR>int 
i=0,j=0,k=0;<BR>while(a[i]!='\0'&amp;&amp;b[j]!='\0')<BR>{<BR>if 
(a[i]&lt;b[j])<BR>{<BR>c[k]=a[i];i++;<BR>}<BR>else<BR>c[k]=b[j++];<BR>k++;<BR>}<BR>c[k]='\0';<BR>if(a[i]=='\0')<BR>p=b+j;<BR>else<BR>p=a+i;<BR>strcat(c,p);<BR>puts(c);<BR>getch();<BR>}<BR>==============================================================<BR>【程序87】<BR>题目:回答结果(结构体变量传递)<BR>1.程序分析:     <BR>2.程序源代码: 
<BR>#include "stdio.h"<BR>#include "conio.h"<BR>struct student<BR>{<BR>int 
x;<BR>char 
c;<BR>}a;<BR>main()<BR>{<BR>a.x=3;<BR>a.c='a';<BR>f(a);<BR>printf("%d,%c",a.x,a.c);<BR>getch();<BR>}<BR>f(struct 
student 
b)<BR>{<BR>b.x=20;<BR>b.c='y';<BR>}<BR>==============================================================<BR>【程序88】<BR>题目:读取7个数(1-50)的整数值,每读取一个值,程序打印出该值个数的*。<BR>1.程序分析:<BR>2.程序源代码:<BR>#include 
"stdio.h"<BR>#include "conio.h"<BR>main()<BR>{<BR>int 
i,a,n=1;<BR>while(n&lt;=7)<BR>{<BR>do<BR>{<BR>scanf("%d",&amp;a);<BR>}while(a&lt;1||a&gt;50);<BR>for(i=1;i&lt;=a;i++)<BR>printf("*");<BR>printf("\n");<BR>n++;<BR>}<BR>getch();<BR>}<BR>==============================================================<BR>【程序89】<BR>题目:某个公司采用公用电话传递数据,数据是四位的整数,在传递过程中是加密的,加密规则如下:<BR>   每位数字都加上5,然后用和除以10的余数代替该数字,再将第一位和第四位交换,第二位和第三位交换。<BR>1.程序分析:<BR>2.程序源代码:<BR>#include 
"stdio.h"<BR>#include "conio.h"<BR>main()<BR>{<BR>int 
a,i,aa[4],t;<BR>scanf("%d",&amp;a);<BR>aa[0]=a%10;<BR>aa[1]=a%100/10;<BR>aa[2]=a%1000/100;<BR>aa[3]=a/1000;<BR>for(i=0;i&lt;=3;i++)<BR>{<BR>aa[i]+=5;<BR>aa[i]%=10;<BR>}<BR>for(i=0;i&lt;=3/2;i++)<BR>{<BR>t=aa[i];<BR>aa[i]=aa[3-i];<BR>aa[3-i]=t;<BR>}<BR>for(i=3;i&gt;=0;i--)<BR>printf("%d",aa[i]);<BR>getch();<BR>}<BR>==============================================================<BR>【程序90】<BR>题目:专升本一题,读结果。<BR>1.程序分析:<BR>2.程序源代码:<BR>#include 
"stdio.h"<BR>#define M 5<BR>main()<BR>{<BR>int a[M]={1,2,3,4,5};<BR>int 
i,j,t;<BR>i=0;j=M-1;<BR>while(i&lt;j)<BR>{<BR>t=*(a+i);<BR>*(a+i)=*(a+j);<BR>*(a+j)=t;<BR>i++;j--;<BR>}<BR>for(i=0;i&lt;M;i++)<BR>printf("%d",*(a+i));<BR>getch();<BR>}</P>
<P><BR>    经典c程序100例==91--100<BR>【程序91】<BR>题目:时间函数举例1<BR>1.程序分析:<BR>2.程序源代码:<BR>#include 
"stdio.h"<BR>#include "conio.h"<BR>#include "time.h"<BR>void 
main()<BR>{<BR>time_t lt; /*define a longint time 
varible*/<BR>lt=time(NULL);/*system time and date*/<BR>printf(ctime(&amp;lt)); 
/*english format output*/<BR>printf(asctime(localtime(&amp;lt)));/*tranfer to 
tm*/<BR>printf(asctime(gmtime(&amp;lt))); /*tranfer to Greenwich 
time*/<BR>getch();<BR>}<BR>==============================================================<BR>【程序92】<BR>题目:时间函数举例2<BR>1.程序分析:      

⌨️ 快捷键说明

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