Computer Science, asked by yashmeet5386, 1 year ago

write an algorithm and draw a flowchart to calculate the sum of 1st 10 natural number

Answers

Answered by PunithaPriya
17

#include <stdio.h>

void main()

{

int j, sum = 0;

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

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

{

sum = sum + j;

printf("%d ",j);

}

printf("\nThe Sum is : %d\n", 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

Similar questions