C++编程。。长见识篇

1034: 求值 Time Limit:  1 Sec   Memory Limit:  128 MB

Submit: 
191   Solved: 14
[ Submit][ Status][ Web Board]

Description

求Sn=1!+2!+3!+4!+5!+…+n!之值,其中n是一个数字。

Input

n

Output

Sample Input

5

Sample Output

153
#include <iostream>
#include <stdio.h>

using namespace std;

long long int sum;
long long int item;
int main()
{
    long long int n;
    scanf("%lld",&n);
    long long int i;
        sum = 0;
        item = 1;
        for(i = 1; i <= n; i ++)
        {
            item *= i;
            sum = sum + item;
        }
        printf("%lld\n",sum);

    return 0;
}
类型名称        字节数    取值范围
signed char       1        -128~+127
short int         2        -32768~+32767
int               4        -2147438648~+2147438647

long int          4        -2147438648~+2141438647

long long int  8      -9223372036854775808~+9223372036854775807


长见识了。。

你可能感兴趣的:(C++编程。。长见识篇)