摘要: /*两个整数的四则运算*/#includeint main(void){int num1,num2,h,c,j,y;/*h和,c差,j积,s商,y余数*/ double s;printf("Enter num1 and num2:");scanf("%d%d",&num1,&num2);h=num1+num2;c=num1-num2;j=num1*num2;s=num1/num2;y=num1%num2;printf("h=%d,c=%d,j=%d,s=%Lf,y=%d\n",h,c,j,s,y);return 0;} 阅读全文
posted @ 2013-10-19 20:54 墨墨萧萧 阅读(182) 评论(0) 推荐(0)
摘要: /*.输入一个整数 x,计算并输出下列分段函数 sign(x) 的值*/#includeint main(void){ int x,y; printf("Enter x:"); scanf("%d",&x); if(x>0){ y=1; } else if(x==0){ y=0; } else if(xint main(void){ int count,n,i; /*count为及格人数*/ double grade,sum; printf("Enter n:"); scanf("%d",&n 阅读全文
posted @ 2013-10-19 16:11 墨墨萧萧 阅读(163) 评论(0) 推荐(0)
摘要: /*利用循环计算多个圆柱体体积*/#includeint main(void){ int n,i; double v,r,h;//自定义函数声明,计算圆柱体体积 double cylinder(double r,double h); printf("Enter n:"); scanf("%d",&n); for(i=1;i0&&h>0){ v=cylinder(r,h); printf("v=%.3f\n",v); } } return 0; } double cylinder(double r,doub 阅读全文
posted @ 2013-10-17 09:14 墨墨萧萧 阅读(213) 评论(0) 推荐(0)
摘要: //计算圆的面积#includeint main(void){ double R,S; printf("Enter R:"); scanf("%Lf",&R); if(R>0){ S=3.14*R*R; } else{ printf("It is wrong");} printf("S=%.2f\n",S); return 0;} #includeint main(){ int c1,c2,c3,c4; scanf("%d%d",&c1,&c2); printf(& 阅读全文
posted @ 2013-10-14 08:48 墨墨萧萧 阅读(170) 评论(0) 推荐(0)
摘要: 心得:刚打第一、二章的时候对代码还不是很熟悉,打的很慢,也容易出错,像丢掉“;”或是漏行的情况会经常发生。打第三站章的时候,由于自认为已经对代码有了一定的熟悉感,所以有些细微的地方就会不注意,有时会漏打一两个字母,或是不小心打错单词。渐渐地我知道,编号的代码如果可以运行也不一定就是正确的,还要看运行结果是否正确。而且空格很重要,有些空格必须有,就像金字塔那个问题(例5-5),printf(“ “),两个引号间必须有空格,还有printf(“ %d”,i) ” 和%之间也必须有空格,要不打出来就会是这样,(如图)经老师指点改正后才和书上的输出结果一致。空格问题有好多地方都要注意。有些就不能有空格 阅读全文
posted @ 2013-10-05 11:31 墨墨萧萧 阅读(740) 评论(0) 推荐(0)
摘要: #includeint main(void){ int count[9]; int i,response; for(i=1;i 8) printf("this is a bad response: %d\n",response); else count[response]++; } printf("result:\n"); for(i=1;iint main(void){ int i; int fib[10]={1,1}; for(i=2;iint main(void){ int i,flag,x; int a[5]; printf("Ente 阅读全文
posted @ 2013-10-05 11:20 墨墨萧萧 阅读(251) 评论(0) 推荐(0)
摘要: #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, doub 阅读全文
posted @ 2013-10-05 11:02 墨墨萧萧 阅读(253) 评论(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; printf("pi=%.4f\n",pi); return 0;} #includeint main(void){ int 阅读全文
posted @ 2013-10-05 10:40 墨墨萧萧 阅读(644) 评论(0) 推荐(0)
摘要: #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-05 10:30 墨墨萧萧 阅读(328) 评论(0) 推荐(0)
摘要: #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;} #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); printf(&q 阅读全文
posted @ 2013-10-04 22:34 墨墨萧萧 阅读(274) 评论(0) 推荐(0)