摘要: #includefloat result_real,result_imag;int main(void){ float imag1,imag2,real1,real2; void complex_prod(float real1,float imag1,float real2,float imag2); void complex_add(float real1,float imag1,float real2,float imag2); printf("Enter 1st complex number(real and imaginary):"); scanf_s(... 阅读全文
posted @ 2013-10-05 23:56 刘睿1994 阅读(87) 评论(0) 推荐(0) 编辑
摘要: /* 输出数字金字塔 */#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'); }} 阅读全文
posted @ 2013-10-05 23:56 刘睿1994 阅读(115) 评论(0) 推荐(0) 编辑
摘要: /* 使用函数求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; ... 阅读全文
posted @ 2013-10-05 23:51 刘睿1994 阅读(110) 评论(0) 推荐(0) 编辑
摘要: #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... 阅读全文
posted @ 2013-10-05 23:39 刘睿1994 阅读(115) 评论(0) 推荐(0) 编辑
摘要: /* 计算圆柱体积 */#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( 阅读全文
posted @ 2013-10-05 23:22 刘睿1994 阅读(63) 评论(0) 推荐(0) 编辑
摘要: /* 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... 阅读全文
posted @ 2013-10-05 23:18 刘睿1994 阅读(116) 评论(0) 推荐(0) 编辑
摘要: /* 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... 阅读全文
posted @ 2013-10-05 23:15 刘睿1994 阅读(94) 评论(0) 推荐(0) 编辑
摘要: /* 输出斐波那契序列的前十项 */#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;} 阅读全文
posted @ 2013-10-05 23:13 刘睿1994 阅读(91) 评论(0) 推荐(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;} 阅读全文
posted @ 2013-10-05 23:12 刘睿1994 阅读(80) 评论(0) 推荐(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;} 阅读全文
posted @ 2013-10-05 23:07 刘睿1994 阅读(84) 评论(0) 推荐(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;} 阅读全文
posted @ 2013-10-05 23:05 刘睿1994 阅读(147) 评论(0) 推荐(0) 编辑
摘要: /* 从输入的n个成绩中选出最高分 */#includeint main(void){ int i,mark,max,n; printf("Enter n:"); scanf_s("%d",&n); printf("Enter %d marks:",n); scanf_s("%d",&mark); max=mark; for(i=1;i<n;i++){ scanf_s("%d",&mark); if(max<mark) max=mark; } printf(& 阅读全文
posted @ 2013-10-05 23:00 刘睿1994 阅读(114) 评论(0) 推荐(0) 编辑
摘要: /* 使用嵌套循环计算1!+2!+3!+…+100! */#includeint main(void){ int i,j; double item,sum; sum=0; for(i=1;i<=100;i++){ item=1; for(j=1;j<=i;j++) item=item*j; sum=sum+item; } printf("1!+2!+3!+…+100!=%e\n",sum); return 0;} 阅读全文
posted @ 2013-10-05 22:49 刘睿1994 阅读(76) 评论(0) 推荐(0) 编辑
摘要: /* 使用函数计算1!+2!+3!+…+100!*/#includedouble fact(int n);int main(void){ int i; double sum; sum=0; for(i=1;i<=100;i++) sum=sum+fact(i); printf("1!+2!+3!+…+100!=%e\n",sum); return 0;}double fact(int n){ int i; double result; result=1; for(i=1;i<=n;i++) result=r... 阅读全文
posted @ 2013-10-05 22:47 刘睿1994 阅读(102) 评论(0) 推荐(0) 编辑
摘要: /* 简单的猜数游戏 */#includeint main(void){ int mynumber=38; int count=0,yournumber; for(count=1;countmynumber) printf("Sorry!your number is bigger than my number!\n"); else printf("Sorry!your number is smaller than my number!\n"); } printf("Game is o... 阅读全文
posted @ 2013-10-05 22:38 刘睿1994 阅读(109) 评论(0) 推荐(0) 编辑
摘要: /* 判断正整数m是否为素数 */#includeint main(void){ int i,m; printf("Enter a number:"); scanf_s("%d",&m); for(i=2;im/2&&m!=1) printf("%d is a prime number!\n",m); else printf("No!\n"); return 0;} 阅读全文
posted @ 2013-10-05 22:37 刘睿1994 阅读(107) 评论(0) 推荐(0) 编辑
摘要: /* 统计一个整数的位数 */#includeint main(void){ int count,number; count=0; printf("Enter a number:"); scanf_s("%d",&number); if(number<0)number=-number; do{ number=number/10; count++; }while(number!=0); printf("It contains %d digits.\n",count); return 0;} 阅读全文
posted @ 2013-10-05 22:34 刘睿1994 阅读(96) 评论(0) 推荐(0) 编辑
摘要: /* 输入一批学生的成绩,以负数作为结束标志,计算平均成绩,并统计不及格人数 */#includeint main(void){ int count,num; double grade,total; num=0; total=0; count=0; printf("Enter grades:"); scanf_s("%lf",&grade); while(grade>=0){ total=total+grade; num++; if(grade<60) count++; ... 阅读全文
posted @ 2013-10-05 22:29 刘睿1994 阅读(84) 评论(0) 推荐(0) 编辑
摘要: /* 用格雷戈里公式计算π的近似值 */#include#includeint main(void){ int denominator,flag; double item,pi; flag=1; denominator=1; item=1.0; pi=0; while(fabs(item)>=0.0001){ item=flag*1.0/denominator; pi=pi+item; flag=-flag; denominator=denominator+2; } pi=pi*4; ... 阅读全文
posted @ 2013-10-05 22:28 刘睿1994 阅读(107) 评论(0) 推荐(0) 编辑
摘要: /* 求解简单的四则运算表达式 */#includeint main(void){ double value1,value2; char op; printf("Type in an expression:"); scanf_s("%lf%c%lf",&value1,&op,&value2); if(op=='+') printf("=%.2f\n",value1+value2); else if(op=='-') printf("=%.2f\n",value 阅读全文
posted @ 2013-10-05 22:18 刘睿1994 阅读(105) 评论(0) 推荐(0) 编辑