Write an algorithm to generate and print 1 to 10.
Answers
Answer:
Here is a simple solution in C/C++
#include <iostream>
int main()
{
for (int index = 1; index <= 10; ++index) {
std::cout << index << std::endl;
}
}
Step-by-step explanation:
An algorithm is a step-by-step solution to a given problem. There are three basic constructs in an algorithm: Linear Sequence: is progression of tasks or statements that follow one after the other. Conditional: IF-THEN-ELSE is decision that is made between two course of actions. Loop: WHILE and FOR are sequences of statements that are repeated a number of times.
This simple program initializes a variable called “index” to the integer value 1. The “for loop” repeats the operation of incrementing the index value on each iteration (repetition) if the value of index is less than or equal 10. The result is the list of numbers from 1 to 10.