摘要:
/* 输出数字金字塔 */#includeint main(void){ void pyramid(int n); pyramid(5); return 0;}void pyramid(int n){ int i,j; for(i = 1;i <= n;i++){ for(j = 1;j <= n-i;j++) printf(" "); for(j = 1;j <= i;j++) printf(" %d ",i); putchar('\n'); }} 阅读全文
摘要:
/* 使用函数求100以内的全部素数 */#include#includeint main(void){ int count,m; int prime(int m); count=0; for(m=2;m<=100;m++){ if(prime(m)!=0){ printf("%6d",m); count++; if(count%10==0) printf("\n"); } } printf("\n");}int prime(int m){ int i,n; ... 阅读全文
摘要:
#include#includeint main(void){ double e,pi; double funpi(double e); printf("Enter e:"); scanf_s("%lf",&e); pi=funpi(e); printf("pi=%f\n",pi); return 0;}double funpi(double e){ int denominator,flag; double item,sum; flag=1; denominator=1; item=1.0; sum=0; wh... 阅读全文
摘要:
/* 计算圆柱体积 */#includeint main(void){ double height,radius,volume; double cylinder(double r,double h); printf("Enter radius and height:"); scanf_s("%lf%lf",&radius,&height); volume=cylinder(radius,height); printf("Volume=%.3f\n",volume); return 0;}double cylinder( 阅读全文
摘要:
/* 45人真好搬45块砖 */#includeint main(void){ int men,women,child; for(men=0;men<=15;men++) for(women=0;women<=22;women++){ child=45-women-men; if(men*3+women*2+child*0.5==45) printf("men=%d,women=%d,child=%d\n",men,women,child); } re... 阅读全文
摘要:
/* 45人正好搬45块砖,版本1 */#includeint main(void){ int child,men,women; for(men=0;men<=45;men++) for(women=0;women<=45;women++) for(child=0;child<=45;child++) if(men+women+child==45&&men*3+women*2+child*0.5==45) printf("men=%d,women=%d,child=%d\n",m... 阅读全文
摘要:
/* 输出斐波那契序列的前十项 */#includeint main(void){ int i,x1,x2,x; x1=1; x2=1; printf("%6d%6d",x1,x2); for(i=1;i<=8;i++){ x=x1 + x2; printf("%6d",x); x1=x2; x2=x; } printf("\n"); return 0;} 阅读全文
摘要:
/* 使用嵌套循环求100以内全部素数 */#include#includeint main(void){ int count,i,m,n; count=0; for(m=2;mn){ printf("%6d",m); count++; if(count % 10==0) printf("\n"); } } printf("\n"); return 0;} 阅读全文
摘要:
/* 逆序输出一个正整数 */#includeint main(void){ int x; printf("Enter x:"); scanf_s("%d",&x); while(x!=0){ printf("%d",x%10); x=x/10; } return 0;} 阅读全文
摘要:
/* 从输入的一批以负数结束的成绩中选出最高分 */#includeint main(void){ int mark,max; printf("Enter marks:"); scanf_s("%d",&mark); max=mark; while(mark>=0){ if(max<mark) max=mark; scanf_s("%d",&mark); }; printf("Max=%d\n",max); return 0;} 阅读全文