2013年10月6日

第六章

摘要: 6-1#includeint main(void){ int i; char ch_lower,ch_upper; for(i=1;i='a'&&ch_lower%c->%d\n",ch_lower,ch_upper,ch_upper%10); } return 0;}6-2#includeint main(void){ char ch='w'; int a=2,b=3,c=1,d,x=10; printf("%d",a>b==c); printf("%d",d=a>b); pr 阅读全文

posted @ 2013-10-06 17:05 chcb111 阅读(149) 评论(0) 推荐(0)

第五章

摘要: 5-1#includeint main(void){ double height,radius,volume; double cylinder(double r,double h); printf("Enter radius and height:"); scanf("%lf%lf",&radius,&height); volume=cylinder(radius,height); printf("Volume=%.3f\n",volume); return 0;}double cylinder(double r,do 阅读全文

posted @ 2013-10-06 17:00 chcb111 阅读(139) 评论(0) 推荐(0)

第四章

摘要: 4-1#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; printf("pi=%.4... 阅读全文

posted @ 2013-10-06 16:50 chcb111 阅读(164) 评论(0) 推荐(0)

第三章

摘要: 3-1#includeint main(void){ int mynumber=38; int yournumber; printf("Input your number:"); scanf("%d",&yournumber); if(yournumber==mynumber) printf("Ok!you are right!\n"); else if(yournumber>mynumber) printf("Sorry!your number is bigger than my number!\n" 阅读全文

posted @ 2013-10-06 16:34 chcb111 阅读(156) 评论(0) 推荐(0)

例2-11

摘要: includedouble fact(int n);int main(void){ int i,n; double result; printf("Enter n:"); scanf("%d",&n); for(i=0;i<=n;i++){ result=fact(i); printf("%d!=%.0f\n",i,result); } return 0;}double fact(int n){ int i; double product; product=1; for(i=1;i<=n;i++){ ... 阅读全文

posted @ 2013-10-06 10:56 chcb111 阅读(131) 评论(0) 推荐(0)

例2-10

摘要: #include#includeint main(void){ int i,n; double power; printf("Enter n:"); scanf("%d",&n); for(i=0;i<=n;i++){ power=pow(2,i); printf("pow(2,%d)=%.0f\n",i,power); } return 0;} 阅读全文

posted @ 2013-10-06 10:53 chcb111 阅读(86) 评论(0) 推荐(0)

例2-8

摘要: #includeint main(void){ int denominator,flag,i,n; double item,sum; printf("Enter n:"); scanf("%d",&n); flag=1; denominator=1; sum=0; for(i=1;i<=n;i++){ item=flag*1.0/denominator; sum=sum+item; flag=-flag; denominator=denominator+2; } printf("... 阅读全文

posted @ 2013-10-06 10:50 chcb111 阅读(91) 评论(0) 推荐(0)

例2-9

摘要: #includeint main(void){ int i,n; double product; printf("Enter n:"); scanf("%d",&n); product=1; for(i=1;i<=n;i++){ product=product*i; } printf("product=%.0f\n",product); return 0;} 阅读全文

posted @ 2013-10-06 10:50 chcb111 阅读(95) 评论(0) 推荐(0)

例2-7

摘要: #includeint main(void){ int i,n,sum; printf("Enter n:"); scanf("%d",&n); sum=0; for(i=1;i<=n;i++){ sum=sum+i; } printf("Sum of numbers from 1 to %d is %d\n",n,sum); return 0;} 阅读全文

posted @ 2013-10-06 10:47 chcb111 阅读(118) 评论(0) 推荐(0)

例2-6

摘要: #includeint main(void){ int fahr,lower,upper; double celsius; printf("Enter lower:"); scanf("%d",&lower); printf("Enter upper:"); scanf("%d",&upper); printf("fahr celsius\n"); for(fahr=lower;fahr<=upper;fahr++){ celsius=(5.0/9.0)*(fahr-32) 阅读全文

posted @ 2013-10-06 10:42 chcb111 阅读(86) 评论(0) 推荐(0)

例2-5

摘要: #include#includeint main(void){ int money,year; double rate,sum; printf("Enter money:"); scanf("%d",&money); printf("Enter year:"); scanf("%d",&year); printf("Enter rate:"); scanf("%lf",&rate); sum=money*pow(1+rate,year); printf 阅读全文

posted @ 2013-10-06 10:22 chcb111 阅读(139) 评论(0) 推荐(0)

例2-4

摘要: #includeint main(void){ double x,y; printf("Enter x (x>=0):\n"); scanf("%lf",&x); if(x<=15){ y=4*x/3; } else{ y=2.5*x-10.5; } printf("y=f(%f)=%.2f\n",x,y); return 0;} 阅读全文

posted @ 2013-10-06 09:46 chcb111 阅读(87) 评论(0) 推荐(0)

导航