write a c++ program to produce following design | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

write a c++ program to produce following design

5555555555 4444 4444 333 333 22 22 1 1

13th Feb 2017, 8:22 AM
akashlina dewanjee
akashlina dewanjee - avatar
6 Answers
+ 12
I've tested with n = 1 to 9 and it seems to do the job. Hope that's what you need :) #include <iostream> using namespace std; int main() { const int n = 5; const int num = n * 2; for (int i = 0; i < num / 2; i++){ for ( int j = 0; j < num / 2 - i; j++ ) { cout<<(num/2 - i); } for ( int j = 0; j < i * 2 - 1; j++ ){ cout<<" "; } for ( int j = 0; j < num / 2 - i; j++ ) { if (!i&&!j) continue; cout<<(num/2 - i); } cout<<endl; } }
13th Feb 2017, 9:04 AM
Nikolay Nachev
Nikolay Nachev - avatar
+ 1
Yes thank you so much!!
13th Feb 2017, 9:20 AM
akashlina dewanjee
akashlina dewanjee - avatar
+ 1
can u explain me the purpose of declaring n?
19th Feb 2017, 1:15 AM
Ălbĕrt Bënzênë
Ălbĕrt Bënzênë - avatar
+ 1
@Albert to make it easy to produce similar design with different base number.
19th Feb 2017, 6:43 AM
Nikolay Nachev
Nikolay Nachev - avatar
0
Bro @Nikoley Nachev how come you win all the challenges Did you hack ?
22nd Feb 2017, 4:12 PM
Ravi kiran
Ravi kiran - avatar
0
Thanks a lot for sharing this program.. I found her more pattern printing C programs here http://www.techcrashcourse.com/2016/02/c-program-to-print-triangle-pyramid-star-pattern.html Hope it helps.
14th Apr 2017, 12:00 PM
Arun Kumar
Arun Kumar - avatar