www.5615.net > 用Do whilE求n的阶乘

用Do whilE求n的阶乘

int s=1;for(int i=1;is=s*i; } 或者 int i=1; int s=1; while(i{ s=s*i; } 求出来的s即n的阶乘

main() { int n,i,f; scanf("pls input 0~9 %d",&n); f=1; i=1; do f=f*i; i++; while(i<=n) pritf("n!=%d";f) }

// for#include<iostream> using namespace std; int main() { int i,n,m=1; cin>>n; for(i=1;i<=n;i++) m*=i; cout<<m<<endl; return 0; }// while#include<iostream> using namespace std; int main() { int i=1,n,m=1; cin>>n; while(i<=n) { m*=i; i++; } cout<<m<<

你好!clear s=___1_____ i=____1____ input "请输入一个数:" to n do while ___i s=s*i _____i=i+1_________ enddo?s &&此行应该输出变量S的值.希望对你有所帮助,望采纳.

#include<stdio.h> int main() {int n,i=1; float f=1.0; printf("please as input an integer>=0.\n"); scanf("%d",&n); while(i<=n)f*=i++; printf("factorial of %d is:%.2f\n",n,f); system("pause"); return 0; }

private sub form_click() '点击窗体运行 dim x as double, n as integer n = val(inputbox("请输入一个整数,注意别太大")) x = 1 while n > 0 x = x * n n = n - 1 wend msgbox "阶乘为" & x end sub要注意的是,由于数字精度的限制,当计算结果大于1百万亿(也就是1后面15个0)时将不再是精确数.因此输入的整数最好不要超过17

#include<stdio.h>int factorial(int n){if (n == 0 || n == 1)return 1;elsereturn n*factorial(n - 1);}int main(){int n,i = 1;printf("求1!+2!++n!的结果\n输入n的值: ");scanf("%d", &n);int sum = 0;while (i<=n){sum += factorial(i); i++;}printf("结果

#include <iostream.h>int main(){ int i=1,x=1,sum=0; do { x*=i; sum+=x; i++; }while (i<=20); cout<<sum<<endl; return 0;}

public class Example { public static void main(String[] args) { int n=5,sum=1; do { sum*=n; n-=1; } while (n>0); System.out.println(sum); }}

//用for int n; int result=1; //在这里输入要计算阶乘的数n for (int i = 1; i <= n; i++) { result *= i; } //在这里输出结果result //用while int n; int result = 1; //在这里输入要计算阶乘的数n while (n>0) { result *= n--; } //在这里输出结果result //用do while int n

友情链接:ymjm.net | lpfk.net | zxqk.net | 9213.net | ceqiong.net | 网站地图

All rights reserved Powered by www.5615.net

copyright ©right 2010-2021。
www.5615.net内容来自网络,如有侵犯请联系客服。zhit325@qq.com