摘要: /* 定义和调用求阶乘函数生成阶乘表 */#includedouble fact(int n);int main(void){ int i,n; double result; printf("Enter n:"); scanf_s("%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; produ... 阅读全文
posted @ 2013-10-01 16:21 刘睿1994 阅读(100) 评论(0) 推荐(0) 编辑
摘要: /* 调用幂函数pow()生成乘法表 */#include#includeint main(void){ int i,n; double power; printf("Enter n:"); scanf_s("%d",&n); for(i=0;i<=n;i++){ power=powl (2,i); printf("pow(2,%d)=%.0f\n",i,power); } return 0;} 阅读全文
posted @ 2013-10-01 16:17 刘睿1994 阅读(108) 评论(0) 推荐(0) 编辑
摘要: /* 输入一个正整数n,求n! */#includeint main(void){ int i,n; double product; printf("Enter n:"); scanf_s("%d",&n); product=1; for(i=1;i<=n;i++){ product=product*i; } printf("product=%.0f\n",product); return 0;} 阅读全文
posted @ 2013-10-01 16:15 刘睿1994 阅读(91) 评论(0) 推荐(0) 编辑
摘要: /* 计算1-1/3+1/5-1/7+… 共n项之和 */#includeint main(void){ int denominator,flag,i,n; double item,sum; printf("Enter n:"); scanf_s("%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=... 阅读全文
posted @ 2013-10-01 16:13 刘睿1994 阅读(94) 评论(0) 推荐(0) 编辑
摘要: /* 计算1+2+3+…+n */#includeint main(void){ int i,n,sum; printf("Enter n:"); scanf_s("%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-01 16:09 刘睿1994 阅读(112) 评论(0) 推荐(0) 编辑