What is a herbal Number?

It is collection of the number beginning from 1 to infinity. That does not encompass 0 or negative numbers.

You are watching: Algorithm to find sum of n numbers

What must be the approach for this program?

As we need to count till the number provided it definitely means we need to use loop till the number. So what have the right to we carry out is we usage a variable to keep the previous variety of the loop and also keep adding the new number.

So us will use for The loop will run n time ,so us declare variable sum and also store the value of sum and iteration that the loop. Print that number.

Flowchart for finding the sum of organic Number

Remove WaterMark from above Flowchart

Pseudocode for finding the amount of herbal Number


Declare a variable n, i and sum as integer;Read number n ;for ns upto n increment i by 1 and i=1sum=sum+i;Print sum;

Here in this Algorithm us declare 3 variables n for storing the number, i for running the for loop and also sum for storing the sum. Read the number n. We use for loop and also increment the loop by 1 upto n. Then we include the numbers and store it in sum. Like if we take n together 4. so in the first iteration i=1 and also sum = 0 + 1 as sum is initialized 0 at the beginning. In the 2nd iteration i=2 and also sum = 1 + 2 as sum was formerly stored together 1 in the 1st iteration. In the third iteration i=3 and also sum = 3 + 3 as sum was previously stored as 3 in the second iteration. In the critical iteration i=4 and also sum = 6 + 4 as sum was previously stored as 6 in the second iteration. and the loop ends and also we publish the value of sum.

See more: Grand Theft Auto 4 Strip Club, Where Can I Find Strip Clubs In Gta 4

Implementation of the routine in C:


#includeint main() { int n, i, sum; printf("Enter the number to find its sum:"); scanf("%d", & n); for (i = 1; ns

Output that the program:


*
17 Upvotes
*
4 Downvotes

Having challenge understanding above Algorithm and also Flowchart? Buy our Notes

Download currently Are You great enough in Algorithms? Test her SkillsStart Quiz Now
*

Play 2048 video game Online and Relax.
*

Algorithm to compute the amount of herbal Number upto offered NumberFlowchart to compute the amount of organic Number upto a NumberC program to calculate sum of organic Numbers upto n