c语言程序打印,C语言必背18个经典程序(可直接打印)

《C语言必背18个经典程序(可直接打印)》由会员分享,可在线阅读,更多相关《C语言必背18个经典程序(可直接打印)(9页珍藏版)》请在人人文库网上搜索。

1、1、/*输出9*9口诀。共9行9列,i控制行,j控制列。*/#include stdio.hmain()int i,j,result;for (i=1;i#include main() float a45,sum1,sum2;int i,j;for(i=0;imain() char c200,c1;int i,j,k;printf(Enter a string: );scanf(%s,c);k=strlen(c);for (i=0,j=k-1;imain() char s80,c;int j,k;printf(nEnter a string: );gets(s);printf(nEnter a。

2、 character: );c=getchar( );for(j=k=0;sj!= 0;j+)if(sj!=c)sk+=sj;sk= 0;printf(n%s,s);10、/*编写一个void sort(int *x,int n)实现将x数组中的n个数据从大到小 排序。n及数组元素在主函数中输入。将结果显示在屏幕上并输出到文件p9_1.out中*/#includevoid sort(int *x,int n) int i,j,k,t;for(i=0;ixk) k=j;if(k!=i) t=xi;xi=xk;xk=t;void main()FILE *fp;int *p,i,a10;fp=fop。

3、en(p9_1.out,w); p=a;printf(Input 10 numbers:);for(i=0;ix) ai+1=ai; i-; /*将比x大的数往后移动一个位置*/a+i=x;j+; /*插入x后元素总个数增加*/for(i=1;ireplace(char *s,char c1,char c2) while(*s!=0) if (*s=c1)*s=c2;s+; main() FILE *fp; char str100,a,b;if(fp=fopen(p10_2.out,w)=NULL) printf(cannot open the filen);exit(0); printf(E。

4、nter a string:n);gets(str);printf(Enter a&b:n);scanf(%c,%c,&a,&b);printf(%sn,str);fprintf(fp,%sn,str);replace(str,a,b);printf(The new string is-%sn,str);fprintf(fp,The new string is-%sn,str);fclose(fp);13、/*在一个字串s1中查找一子串s2,若存在则返回子串在主串中的起始位置,不存在则返回-1。*/main() char s16=thisis;char s25=is;printf(%dn,se。

5、arch(s1,s2);system(pause);int search(char s1,char s2) int i=0,j,len=strlen(s2);while(s1i) for(j=0;j=len)return i;else i+;return -1;14、/*用指针变量输出结构体数组元素。*/struct studentint num;char *name;char sex;int age;stu5=1001,lihua,F,18,1002,liuxing,M,19,1003,huangke,F,19,1004,fengshou,F,19,1005,Wangming,M,18;ma。

6、in()int i;struct student *ps;printf(Num tNametttSextAgetn); /*用指针变量输出结构体数组元素。*/for(ps=stu;psnum,ps-name,ps-sex,ps-age);/*用数组下标法输出结构体数组元素学号和年龄。*/for(i=0;inum,p-name,p-age);p=p-next;while(p!=NULL);16、/*输入一个字符串,判断其是否为回文。回文字符串是指从左到右读和从右到左读完全相同的字符串。*/#include #include #includemain() char s100;int i,j,n;p。

7、rintf(输入字符串:n);gets(s); n=strlen(s);for(i=0,j=n-1;i=j) printf(是回文串n);else printf(不是回文串n);17、/*冒泡排序,从小到大,排序后结果输出到屏幕及文件myf2.out*/#includevoid fun(int a,int n)int i,j,t;for(i=0;iaj+1) t=aj;aj=aj+1;aj+1=t;main()int a10=12,45,7,8,96,4,10,48,2,46,n=10,i;FILE *f;if(f=fopen(myf2.out,w)=NULL)printf(open file。

8、 myf2.out failed!n);fun(a,10);for(i=0;idouble countpi(double eps) /*eps为允许误差*/int m=1;double temp=1.0,s=0;while(temp=eps) s+=temp;temp=temp*m/(2*m+1);m+;return(2*s);main()FILE *fp;double eps=1e-5,pi;if(fp=fopen(p7_3.out,w)=NULL) printf(cannot open the filen);exit(0); pi= countpi(eps);printf(pi=%lfn,pi);fprintf(fp,pi=%lfn,pi);fclose(fp);9欢迎下载。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值