158k views
11 votes
write an algorithm and draw a flowchart to calculate the sum of of the first 10 natural numbers starting from 1​

1 Answer

12 votes

Answer:

#include <stdio.h>

void main()

{

int j, sum = 0;

printf("The first 10 natural number is :\\");

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

{

sum = sum + j;

printf("%d ",j);

}

printf("\\The Sum is : %d\\", sum);

}

Within a loop

Step 1: Initialize a variable to 1 (say x=1)

Step 2: Specifiy the condition

In this case x<=10

Step 3: Increment the variable by 1

using increment operator x++

OR

simply x+=1(x=x+1)

Step 4: Print the value of variable

Terminate the loop

Step-by-step explanation:

User Jahid Mahmud
by
4.3k points