Computer Science, asked by shribhowmick2001, 1 month ago

Write an algorithm and DAF to add first 10 natural numbers.​

Attachments:

Answers

Answered by Equestriadash
5

Algorithm:

1. Assign a variable to represent the sum.

2. Start a loop within the range of 1 to 11.

3. Add the traversing elements to the variable representing the sum.

4. Print the variable once the loop stops.

A Python program for the same has been given below:

\tt de f\ sum\_10():\\{\ \ \ \ \ } \sf \#assigning\ a\ variable\ to\ represent\ the\ sum\\{\ \ \ \ \ } \tt s\ =\ 0\\{\ \ \ \ \ } \sf \#starting\ a\ lo op\\{\ \ \ \ \ } \tt for\ i\ in\ range(1,\ 11):\\{\ \ \ \ \ } \sf \#adding\ the\ traversing\ elements\ into\ the\ sum\ variable\\{\ \ \ \ \ } \tt s\ =\ s\ +\ i\\{\ \ \ \ \ } \sf \#printing\ the\ ou tput\\{\ \ \ \ \ } \tt print(s)

Python has an in-built function called \tt de f that is used to create user-defined functions. As per the algorithm, we assign a variable 's' to represent the sum and start a loop with the range as (1, 11), since natural numbers start from 1 and the \tt for loop always excludes the last element in the range, i.e., 11. We add the traversing elements to the variable 's' and print it.


Equestriadash: Thanks for the Brainliest! ^_^"
Similar questions