Computer Science, asked by samarvirk8619, 1 year ago

Write a program using while loop to generate the first 10 natural numbers and their sum.

Answers

Answered by orangesquirrel
41

#include <stdio.h>

#include<conio.h>

void main()

{

int a, sum = 0;

printf("The first 10 natural numbers are as follows :\n");

for (a= 1; a <= 10; a++)

{

sum = sum + a;

printf("%d ",a);

}

printf("\nThe Sum of the 10 natural numbers is : %d\n", sum);

}

Answered by mindfulmaisel
12

"No programming language has been specified in the question. So, I am going to answer the question with code in C programming language. The program in C programming language which uses a while loop to generate the first 10 natural numbers and their sum is as follows:

#include <stdio.h>

#include<conio.h>

void main()

{

int a, sum = 0;

printf("The first 10 natural numbers are as follows :\n");

for (a= 1; a <= 10; a++)

{

sum = sum + a;

printf("%d ",a);

}

printf("\nThe Sum of the 10 natural numbers is : %d\n", sum);

}"

Similar questions