當前位置:
首頁 >
1131: 零起点学算法38——求阶乘和
發布時間:2025/7/14
31
豆豆
生活随笔
收集整理的這篇文章主要介紹了
1131: 零起点学算法38——求阶乘和
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1131: 零起點學算法38——求階乘和
Time Limit: 1 Sec??Memory Limit: 64 MB?? 64bit IO Format: %lldSubmitted: 2719??Accepted: 1736
[Submit][Status][Web Board]
Description
輸入一個正整數n(n<=10),計算
S=1!+2!+3!+...+n!?
?
Input
輸入一個正整數n(n<=10)(多組數據)
?
Output
輸出S(每組數據一行)
?
Sample Input
2?
Sample Output
3?
Source
零起點學算法
1 #include<stdio.h> 2 int main(){ 3 int n; 4 while(scanf("%d",&n)!=EOF){ 5 long long s=0; 6 for(int i=1;i<=n;i++){ 7 long long sum=1; 8 for(int j=i;j>0;j--){ 9 sum*=j; 10 } 11 s+=sum; 12 } 13 printf("%lld\n",s); 14 } 15 return 0; 16 }?
轉載于:https://www.cnblogs.com/dddddd/p/6680406.html
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的1131: 零起点学算法38——求阶乘和的全部內容,希望文章能夠幫你解決所遇到的問題。