+ 1
write a c++ program to produce following design
5555555555 4444 4444 333 333 22 22 1 1
6 ответов
+ 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;
}
}
+ 1
Yes thank you so much!!
+ 1
can u explain me the purpose of declaring n?
+ 1
@Albert to make it easy to produce similar design with different base number.
0
Bro @Nikoley Nachev how come you win all the challenges
Did you hack ?
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.