Answer:
The loop in cpp language is as follows.
for(int n=10; n<=90; n++)
{
cout<<n<<" ";
count = count+1;
if(count==10)
{
cout<<""<<endl;
count=0;
}
}
Step-by-step explanation:
1. The expected output is obtained using for loop.
2. The loop variable, n is initialized to the starting value of 10.
3. The variable n is incremented by 1 at a time, until n reaches the final value of 90.
4. Every value of n beginning from 10 is displayed folllowed by a space.
5. When 10 numbers are printed, a new line is inserted so that every line shows only 10 numbers.
6. This is achieved by using an integer variable, count.
7. The variable count is initialized to 0.
8. After every number is displayed, count is incremented by 1.
9. When the value of count reaches 10, a new line is inserted and the variable count is initialized to 0 again. This is done inside if statement.
10. The program using the above loop is shown below along with the output.
PROGRAM
#include <stdio.h>
#include <iostream>
using namespace std;
int main()
{
int count=0;
for(int n=10; n<=90; n++)
{
cout<<n<<" ";
count = count+1;
if(count==10)
{
cout<<""<<endl;
count=0;
}
}
return 0;
}
OUTPUT
10 11 12 13 14 15 16 17 18 19
20 21 22 23 24 25 26 27 28 29
30 31 32 33 34 35 36 37 38 39
40 41 42 43 44 45 46 47 48 49
50 51 52 53 54 55 56 57 58 59
60 61 62 63 64 65 66 67 68 69
70 71 72 73 74 75 76 77 78 79
80 81 82 83 84 85 86 87 88 89
90
1. In the above program, the variable count is initialized inside main() but outside for loop.
2. The program ends with a return statement since main() has return type of integer.
3. In cpp language, use of class is not mandatory.