Computer Science, asked by urvashirastogi7, 1 year ago

Write a program in while loop to generate first 10 natural numbers and their sum

Answers

Answered by chalotragourav
2

#include <stdio.h>

int main()

{

   int n, i, sum = 0;

   

   printf("Enter a positive integer: ");

   scanf("%d",&n);

   i = 1;

   while ( i <=n )

   {

       sum += i;

       ++i;

   }

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

   return 0;

}

Similar questions