Wednesday, January 14, 2015

SUM OF ‘N’ NATURAL NUMBERS

PROGRAM:

#include<stdio.h> main()

{

int i,n,sum=0; printf("Enter the range\n"); scanf("%d",&n);

i=1;

while(i<=n)

{

sum=sum+i;

i++;

}

printf("\nThe sum of first %d numbers is %d\n",n,sum);

}




 OUTPUT:

Enter the range 16


The sum of first 16 numbers is 136

No comments:

Post a Comment