C Program To Print Sum Of Natural Numbers Using For Loop

C Program To Print Sum Of Natural Numbers Using For Loop

Code
// WAP To Print Sum Of Natural Numbers Using For Loop...

#include <stdio.h>
int main()
{
    int n, sum = 0;
    printf("Enter Number:\n");
    scanf("%d", &n);

    for (int i = 1; i <= n; i++)
    {
        sum = sum + i;
    }
    printf("Sum Of Numbers:%d", sum);
    return 0;
}
Output
Enter Number:
100
Sum Of Numbers:5050

Post a Comment