Powered By Blogger

Feb 11, 2025

16. Calculate the Sum of First N Natural Numbers

 #include <stdio.h>

int main() {

    int n, sum = 0;

    printf("Enter a positive integer: ");

    scanf("%d", &n);

    for (int i = 1; i <= n; i++)

        sum += i;

    printf("Sum: %d\n", sum);

    return 0;

}


No comments:

Post a Comment

Featured Post

Data Analysis

    What is data analysis and its significance?   Data analysis is the process of collecting, transforming, and organizing data to dr...

Popular Posts