//write A programme to print all natural number from 1 to n using while loop
#include "stdio.h"
int main (){
int n,i,sum;
printf ("Enter the last number of the series :\n");
scanf ("%i",&n);
i=1;
while (i<=n){
sum=sum+i;
i++;
}
printf ("The sum of the series is %i",sum);
return 0;
}
output :
Enter the last number of the series :
10
The sum of the series is 55
No comments:
Post a Comment