bshy.net
当前位置:首页>>关于c语言编程 :输入整数n,求n的阶乘 并输出.的资料>>

c语言编程 :输入整数n,求n的阶乘 并输出.

#include int main() { int num; printf("input num"); scanf("%d",&num); int Sum=1; for(int i=1;i

#includevoid main(){int n,m,i;printf("输入n的值:"); scanf("%d",&n);if(n==0||n==1){m=1;printf("n的阶乘为:%d\n",m);}else{m=1;for(i=n;i>0;i--)m=m*i;printf("n的阶乘为:%d\n",m);}}//刚写的,运行通过

思路:所谓n的阶乘就是从1到n的累积,所以可以通过一个for循环,从1到n依次求积即可。 参考代码: #include "stdio.h" int main() {int n,i,s=1;scanf("%d",&n);for(i=1;i

#include int main() { int n,t,i; t=1; scanf("%d",&n); for(i=0;i

#include double fun ( int n ) { double result = 1.0 ; if (n == 0) return 1.0 ; while( n >1 && n < 170 ) result *= n--; return result ; } main ( ) { int n ; printf("Input N:") ; scanf("%d", &n) ; printf("\n\n%d! =%lf\n\n", n, fu...

#includelong fac(unsigned n){if (n == 0 || n == 1){return 1;}else{return (n * fac(n - 1));}}int main(){unsigned ui;printf("输入计算的阶乘:");scanf("%u", &ui);printf("%u的阶乘为:%u\n", ui, fac(ui));return 0;} 注意: 0的阶乘是1...

i=i+1 改为 i=i-1;

#include int main() {int n,i,t=1,s=0; scanf("%d",&n); for(i=1;i

源程序如下: #include //定义头文件 int main()//声明主函数 { int n,i=1,jc=1;//设定数据类型 printf("input n: ");//输入一个正整数 scanf("%d", &n);//输入 while (i

//#include "stdafx.h"//vc++6.0加上这一行.#include "stdio.h"int main(void){ int n,i,fact; while(1){ printf("Input n(int 0

网站首页 | 网站地图
All rights reserved Powered by www.bshy.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com