C program to add n natural numbers from 1






#include<stdio.h>
int main(){

int n,sum = 0;

    printf("Enter any positive number: ");
    scanf("%d",&n);

    for(i=1;i<=n;i++){
        sum = sum + 1;
    }

printf("Sum of n numbers: %s",sum);

    return 0;
}




0 comments:

C compiler: gcc 4.1.2