Answer:
#include<iostream>
using namespace std;
//main function
int main(){
//nested for loop
for(int i=9;i>=1;i--){
for(int j=1;j<=i;j++){
cout<<j<<" "; //display
}
}
return 0;
}
Explanation:
Include the library iostream for using the input/output instruction in the c++ programming.
Create the main function and takes nested for loop. Nested for loop means, for loop inside the another for loop.
For every value of outside for loop, inside for loop execute.
we make outer for loop in decreasing format, means it start from 9 and goes to 1 and inside for loop make in increasing format, means loop start from 1 and it goes to that value which is provided by the outer loop.
and print the output for every cycle.
Lets dry run the code:
the outer loop starts from 9 and it checks the condition 9>=1, condition true. then the program moves to the inner loop which starts from 1 and goes to the 9.
first, it also checks the condition 1 <= 9, condition true and prints the number from 1 to 9.
then, i is reduced by 1. it means i become 8.
then, the above process continues from 1 to 8 and so on...
the loop process will terminate if the outer loop terminate.
Finally, we get the output.