phfb.net
当前位置:首页 >> C程序设计求5的阶乘 >>

C程序设计求5的阶乘

#include "stdio.h" main() { double m; int fact(int); m=1.0/fact(5); printf("%ld",m); } int fact(int j) { int sum; if(j==0) sum=1; else sum=j*fact(j-1); return sum;}

##include <stdio.h> int Multi(int n) { if(n == 1) return 1; else return n*Multi(n-1); } void main() { printf("Result : %d\n",Multi(5)); }

#include int fac(int n); int main() { int sum = 0; sum = fac(1) + fac(3) + fac(5); printf("%d",sum); return 0; } int fac(int n) { int i = 0; int sum = 0; for(; i

#include <stdio.h> void main() { int mdi,n; mdi= 1; printf("input :\n"); scanf("%d",&n); while (n>0) { mdi=mdi*n; n--; } printf("output :%d \n",mdi); } #include <stdio.h> void main() //该程序的n必须大于0,这是针对你的问题所设计的 { int mdi,

#include void main() { int s=1,i; for(i=1;i

#include int main() { int i,sum=1; for(i=1;isum*=i; printf("%d",sum); return 0; }

#include void main() { int n=5; int sum=1; for(i=1;i sum*=i; printf("%d",sum); }

void Factorial(int Cnt) { int i; unsigned long Multi = 1; for(i = Cnt; i > 0; i--) { Multi *= Cnt; //先做乘数 printf("%d * ", Cnt); //假如为5则打印 5* 4 * 3 * 2 * 1(Cnt * Cnt-1 * Cnt-1-1 * * 1) Cnt -= 1; //然后减1 } //当减到0时就跳出for选循环 printf(" = %d\n\r", Multi); //此处打印结果为" = 120" }//假如传入5,则打印信息为5 * 4 * 3 * 2 * 1 = 120

#include <stdio.h> int main() { int i=0; long temp=1; long sum=0; for(i=1;i<=20;i++) { temp*=i; sum+=temp; } printf("sum=%ld\n",sum); return 0; } 利用for循环期求出第n项阶乘的积,然后前n-1项的阶乘的和加上第n项阶乘就是所求.

#include<stdio.h>int main(){int ans=1;int i;for(i=1;i<=5;i++)ans=ans*i; //或写成ans*=iprintf("%d",ans);return 0;}

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