In: Computer Science
(C++) Write a nested loop that reads an integer n (n>0) from the keyboard and print out "n" lines as follows:
0
0 1
0 1 2
0 1 2 3
…
0 1 2 3 … n-1
The output is:
code for copy:
#include<iostream>
using namespace std;
int main()
{
//declare an integer variable n
int n;
cout<<"Enter the value of n: ";
//read the value of n
cin>>n;
//nested for loop to print the following pattern
cout<<"The pattern is :"<<endl;
for(int i=0;i<n;i++)
{
for(int j=0;j<=i;j++)
{
cout<<j<<" ";
}
cout<<endl;
}
}
I HOPE THIS WILL HELP YOU..........IF YOU HAVE ANY DOUBTS REGARDING IT PLEASE LET ME KNOW IN THE COMMENT SECTION.