资源描述:
《C语言程序设计 入门源代码代码集合教案资料.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、演示1#includevoidprint_star(void){printf("*****************");}voidprint_welcome(void){printf("Clanguage,welcome!");}voidmain(){print_star();print_welcome();print_star();getchar();}演示2#include"stdio.h"intsum(inti,intj){return(i+j);}voidmain(){intn1,n2;printf("input2numbe
2、rs:");scanf("%d%d",&n1,&n2);printf("thesum=%d",sum(n1,n2));getchar();}演示3#include"stdio.h"intmaxnum(int,int,int);main(){inta,b,c;printf("Pleaseenter3numbers:");scanf("%d,%d,%d",&a,&b,&c);printf("Maxnumis%d",maxnum(a,b,c));return0;}intmaxnum(intx,inty,intz){intmax=x;if(y>max
3、)max=y;if(z>max)max=z;returnmax;}演示4#includeints1(intn){intj,s;s=0;for(j=1;j<=n;j++)s=s+j;returns;}intsum(intn){inti,s=0;for(i=1;i<=n;i++)s=s+s1(i);returns;}voidmain(){intn;printf("n:");scanf("%d",&n);printf("s=%d",sum(n));}演示5#includevoidfunc(intn){inti;for(i=n
4、-1;i>=1;i--)n=n+i;printf("n=%d",n);}voidmain(){intn;printf("Inputn:");scanf("%d",&n);func(n);printf("n=%d",n);}演示6#includevoidswap(inta,intb){inttemp;temp=a;a=b;b=temp;printf("swap:a=%d,b=%d",a,b);}voidmain(){inta,b;a=3;b=10;swap(a,b);printf("a=%d,b=%d",a,b);}演示7#i
5、ncludeintfunc(inta,intb){intc;c=a+b;returnc;}voidmain(){intx=6,y=7,z=8,r;r=func((x--,y++,x+y),z--);printf("%d",r);}演示8#includemax(floatx,floaty){returnx>y?x:y;}voidmain(){printf("%d",max(2,3.5));}演示9#includeintsum(intn){inti,s=0;for(i=0;i<=n;i++)s=s+i
6、;returns;}voidmain(){intm,sn;scanf("%d",&m);sn=sum(m);printf("thesumis%d",sn);}演示10#includevoidswap(intx,inty);intmain(){inta,b;printf("input2numbers:");scanf("%d,%d",&a,&b);printf("inputnumberis:a=%d,b=%d",a,b);swap(a,b);printf("input2numbersis:a=%d,b=%d",a,b);ret
7、urn0;}voidswap(intx,inty){inttemp;temp=x;x=y;y=temp;printf("swapnumberis:x=%d,y=%d",x,y);}演示11#include"stdio.h"#defineK3#defineN5longf2(intn,intk){longpower=n;inti;for(i=1;i8、ntmain(void){printf("sumof