另一種階乘問題

來源:互聯網
上載者:User

標籤:

描述

  大家都知道階乘這個概念,舉個簡單的例子:5!=1*2*3*4*5.現在我們引入一種新的階乘概念,將原來的每個數相乘變為i不大於n的所有奇數相乘例如:5!!=1*3*5.現在明白現在這種階乘的意思了吧!

  現在你的任務是求出1!!+2!!......+n!!的正確值(n<=20)

輸入
  第一行輸入一個a(a<=20),代表共有a組測試資料
  接下來a行各行輸入一個n.
輸出
  各行輸出結果一個整數R表示1!!+2!!......+n!!的正確值
範例輸入
235

範例輸出

523
 1 #include <stdio.h> 2  3 int main() 4 { 5     int s, n, i, j, t, sum; 6     scanf("%d", &s); 7     for (i = 0; i < s; i++) 8     { 9         scanf("%d", &n);10         sum = 0;11         t = 1;12         for (j = 1; j <= n; j++)13         {14             if (j % 2 == 1)15             {16                 t *= j;17             }18             sum += t;19         }20         printf("%d\n", sum);21     }22     return 0;23 }

 

另一種階乘問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.