+ 1

How to print the following code:

plz help i am a newbie. i want to print the following code in c++ and it should be centered: A AB ABC ABCD plz reply keeping in mind that im a newbie and the code should be simple using the for loop

19th Mar 2018, 1:07 PM
Shaurya Upadhyaya
Shaurya Upadhyaya - avatar
10 odpowiedzi
+ 16
1) make a loop for number of rows [r=0 to r=n] 2) make a loop , [inside 1) ]for spaces in left [any n>(length+1)/2 to 0] //decrease n after each iteration of 1) by 2 3) then make a loop for characters[inside 1) ] start from k=1 to k=0 //with every iteration of 1) , increase value of k by 2 4) then jump to next line //thats a very basic way of making these patterns //edit : can't write the code ... I'm very beginner give it a try by your own first , and then either comment here or on my code ... will correct it if some error occurs
19th Mar 2018, 1:12 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 14
//modified code of Ashraf for spaces //still , U should not see them & give it a try by yourself ... #include <iostream> using namespace std; int main() { for(int i = 0; i < 6; i++) { for(int j = 2*(6-i); j >0 ; j-=2) cout<<char(' '); for(int j = 0; j < i; j++) cout<<char('A' + j); cout<<endl; } return 0; }
19th Mar 2018, 1:20 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 7
its pretty easy .. all you need to do is think what do you want to print and how many times you want it ..
19th Mar 2018, 6:59 PM
Ashraf Al_Absi
Ashraf Al_Absi - avatar
+ 5
https://code.sololearn.com/cvir0AJ3aC84/?ref=app just made it.. look like homework ☺
19th Mar 2018, 1:20 PM
Scooby
Scooby - avatar
19th Mar 2018, 6:58 PM
Ashraf Al_Absi
Ashraf Al_Absi - avatar
+ 4
https://code.sololearn.com/cNgWP6Qjq0Hi/?ref=app
19th Mar 2018, 1:17 PM
Ashraf Al_Absi
Ashraf Al_Absi - avatar
+ 4
just made it now..
19th Mar 2018, 1:17 PM
Ashraf Al_Absi
Ashraf Al_Absi - avatar
+ 4
if you want capital just change 'a' to 'A'
19th Mar 2018, 1:17 PM
Ashraf Al_Absi
Ashraf Al_Absi - avatar
0
can u write the code?
19th Mar 2018, 1:13 PM
Shaurya Upadhyaya
Shaurya Upadhyaya - avatar
0
what if we change the alignment like A BA CBA DCBA the order does not matter
19th Mar 2018, 2:19 PM
Shaurya Upadhyaya
Shaurya Upadhyaya - avatar