c语言 几个重要的代码.doc_第1页
c语言 几个重要的代码.doc_第2页
c语言 几个重要的代码.doc_第3页
c语言 几个重要的代码.doc_第4页
免费预览已结束,剩余1页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

#include /递归函数求阶乘 double fun(int x)double result;if(x=1|x=0)result=1;elseresult=fun(x-1)*x;return result;void main()int n;printf(Enter n: );scanf(%d,&n);printf(%d!=%.0fn,n,fun(n); #include /将字符串str2的值赋给str1 void main()int i,n;char str1100=Good Morning!a*b*c*d*e*f*g,str250=C program;for(i=0;str1i!=0;i+);n=i;for(i=0;str2i!=0;i+)str1i=str2i; while(in)str1i+=0;puts(str1);printf(n); #include / 从键盘输入一个字符串,放在str2中,再将str2和str1连接void main()int i,j,n;char str150=Good Morning !-,str220;gets(str2);for(i=0;str1i!=0;i+);n=i;for(i=n,j=0;str2j!=0;i+,j+)str1i=str2j;str1i=0;puts(str1);printf(n); #include/从键盘输入10个数,冒泡排序,从小到大输出void main()int i,j,temp,a10;for(i=0;i10;i+)scanf(%d,&ai);for(i=1;i10;i+)for(j=0;jaj+1)temp=aj; aj=aj+1; aj+1=temp;for(i=0;i10;i+)printf(%-2d,ai);printf(n); #include/从键盘输入10个数,选择排序,从小到大输出void main()int i,j,temp,a10;for(i=0;i10;i+)scanf(%d,&ai);for(i=0;i10;i+)for(j=i+1;j10;j+)if(ajai)temp=ai; ai=aj; aj=temp;for(i=0;i10;i+)printf(%-2d,ai);printf(n); #include/输出所有的水仙花数 main()int i,a,b,c;for(i=100;i1000;i+)a=i/100;b=i/10%10;c=i%10;if(i=a*a*a+b*b*b+c*c*c)printf(%5d,i);printf(n); #include/输出从m到n所有的素数int main(void)int i,j,m,n,c=0;printf(Enter m,n: );scanf(%d,%d,&m,&n);printf(All the prime numbers between %d and %d:n,m,n);for(i=m;in;i+)for(j=2;ji/2)printf(%5d,i);c+; if(c%10=0) printf(n);printf(n);return 0;#include/从键盘输入一串字符,统计其中字母,数字,空格,和其他字符的个数 main()int i,charactor,digit,blank,other;char ch;charactor=blank=digit=other=0;for(i=0;(ch=getchar()!=n;i+)if(ch=A&ch=a&ch=0&ch=9)digit+;if(ch= )blank+;printf(charactor=%dndigit=%dnblank=%dn other=%dn,charactor,digit,blank,other=i-charactor-digit-blank); #include /字符串比较大小#include string.hint main(void)char string120,string220;printf(Enter string1:

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论