+ 1

How to get an output like the following:

# ## ### #### for an input x=4, with proper white spaces.

6th Nov 2016, 3:46 PM
Shahbaz
Shahbaz - avatar
6 Answers
+ 3
edit: implemented in c++ #include <iostream> using namespace std; int main() { int i,j; int input = 4; for (i = 0; i<input ; i++){ for(j= 0;j<input;j++){ if(j >= (input-i-1)) { cout << "#"; } else{ cout << "
quot;; } /*use spaces here instead of $ to run on terminal... use $ to run on soloLearn*/ } cout << endl ; } return 0; }
6th Nov 2016, 3:55 PM
Paul Kabira
Paul Kabira - avatar
+ 3
#include <iostream> using namespace std; int main() { int i,j,n; cout<<"Enter Input:\n"; cin>>n; for(i=0;i<n;i++) { for(j=0;j<n;j++) { if(j>=(n-i-1)) { cout<<"#"; } else { cout<<" "; } } cout<<"\n"; } return 0; }
6th Nov 2016, 5:16 PM
SANKALP PHADKE
SANKALP PHADKE - avatar
+ 1
you r welcome shahbaz , in those for loops if you initialize i = j = 1 then use '<=' condition in both loops and change the if condition 'if( j>= input -i)'
6th Nov 2016, 4:22 PM
Paul Kabira
Paul Kabira - avatar
+ 1
Loops are the most interesting topic I've encountered till yet.
14th Nov 2016, 3:33 PM
Random
0
Thank you Kabira, just had to put a '<=' in the first loop.
6th Nov 2016, 4:14 PM
Shahbaz
Shahbaz - avatar
0
Got you... ^_^
6th Nov 2016, 4:32 PM
Shahbaz
Shahbaz - avatar