Sum of First N Natural Numbers (Do–While Loop)

 #include<stdio.h>

int main()

{

    int n,i=1,sum=0;

    printf("Enter n: ");

    scanf("%d",&n);


    do

    {

        sum=sum+i;

        i++;

    }while(i<=n);

    printf("Sum = %d",sum);

}

Comments

Popular posts from this blog

Single Program Using All Automatic String Functions

C program for subtraction of two matrices (2D Arrays)

C program for Multiplication of Two matrices