资源描述:
《C语言基础练习代码.pdf》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、5,2,1元面额组合的问题#includemain(){inta,b,c,t;for(a=0;a<=2;a++)for(b=0;b<=5;b++){c=10-5*a-2*b;t=5*a+2*b+c;if(t==10)printf("%d张5元,%d张2元,%d张一元",a,b,c);}简单穷举法啊100到200间被2和3整除的数、#includemain(){inti=100;for(;i<=200;i++){if(i%2==0&&i%3==0)printf("%-4d",i);}
2、putchar('');}Do……while例子#includemain(){ints=0,i=1;do{s=s+i;i++;}while(i<=100);printf("1+2+3+……+100=%d",s);}For例子#includemain(){ints=0,i;for(i=1;i<=100;i++)s=s+i;printf("1+2+3……+100=%d",s);}百钱买百鸡#includemain(){inta,b,c,s;for(a=0;a<
3、=33;a++)for(b=0;b<=100;b++){c=100-a-b;s=3*a+b+c/3;if(s==100)printf("%d%d%d",a,b,c);}}打印棱形#includemain(){inti,j,k;for(i=1;i<=4;i++){for(j=1;j<=4-i;j++)printf("");for(j=1;j<=2*i-1;j++)printf("*");printf("");}for(i=1;i<=3;i++){for(j=1;j<=i;j++)printf(""
4、);for(j=1;j<=2*(4-i)-1;j++)printf("*");printf("");}}打印豪华版圣诞树#includemain(){inti,j;for(i=1;i<=4;i++){for(j=1;j<=10-i;j++)printf("");for(j=1;j<=2*i-1;j++)printf("*");printf("");}for(i=2;i<=6;i++){for(j=1;j<=10-i;j++)printf("");for(j=1;j<=2*i-1;j++)prin
5、tf("*");printf("");}for(i=2;i<=8;i++){for(j=1;j<=10-i;j++)printf("");for(j=1;j<=2*i-1;j++)printf("*");printf("");}for(i=2;i<=10;i++){for(j=1;j<=10-i;j++)printf("");for(j=1;j<=2*i-1;j++)printf("*");printf("");}for(i=1;i<=3;i++){for(j=1;j<=8;j++)printf("");fo
6、r(j=1;j<=3;j++)printf("*");printf("");}printf("圣诞快乐!O(^_^)O");}求1到n的素数#include#includemain(){intn,m,i,j,flag;printf("请输入第n个数:");scanf("%d",&n);for(i=2;i<=n;i++){flag=1;m=sqrt(i);for(j=2;j<=m;j++){if(i%j==0){flag=0;break;}if(flag==1)printf
7、("%7d",i);}}printf("");}求素数#include#includemain(){longn;intx,i,y;printf("请输入一个数:");scanf("%ld",&n);for(i=1;i<=n;i++){x=sqrt(i);for(y=2;y<=x;y++){if(i%y==0)break;printf("%-7ld",i);}}求整数X是不是素数#include#includemain(){intx,i,y;pri
8、ntf("请输入一个数:");scanf("%d",&x);y=sqrt(x);for(i=2;i<=y;i++)if(x%i==0)break;if(i>y)printf("%d是素数",x);printf("%d不是素数",x);}求最大公约数#includemain(){inta,