累加和

    xiaoxiao2024-10-29  76

    累加和 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Problem Description

    题目描述: 编写程序,求自然数1至n(n>1)的累加和。其中n的值从键盘输入。(难度级别—容易) Input

    输入一个自然数赋给变量n。 Output

    输出自然数1至n的累加和。 Sample Input

    5 Sample Output

    The sum of 1 to 5 is 15 Hint

    Source

    本文旨在为非计算机专业同学提供帮助

    #include <stdio.h> int main() { int n,i; scanf("%d",&n); int s=0; for(i=0;i<=n;i++) s=s+i; printf("The sum of 1 to %d is %d",n,s); return 0; }
    最新回复(0)