Upright right half triangle of numbers
Print the right half upright pyramid of increasing numbers.
Learning Objectives
- Learning to print half triangle of increasing numbers series.
Source Code
|
|
Related ( ? ) : |
Run Output
Code Understanding
int cnt; cout<<“Give row count : “; cin>>cnt; //Row count collected from user
for(int i=1;i<=cnt;i++) //Outer loop for row count
{
for(int j=1;j<=i;j++) //Inner Loop for column count, Column keep increasing with each iteration
cout<<j<<” “; //The inner loop count is printed, first it will be 1, then 1 2, then 1 2 3 and so on
cout<<“n”; //Next line after inner loop
}
}
Notes
- Replacing j of the inner loop with any character prints the character pattern.
Common Errors
- Some time student forget to change the newline outside inner loop and inside outer loop, or some time they do it inner loop. Experiment yourself and understand the error.
Suggested Filename(s): pat-rht-num.cpp,prht-num.cpp
Created: 19-Jan-2018 23:32 | Updated: 19-Jan-2018 23:40|
