Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,990 questions

51,935 answers

573 users

How to print N size triangle of zeros with 1 to N numbers in the center in C++

1 Answer

0 votes
#include <iostream>

int main() {
    int N = 9;
    
    for (int i = 1; N > 0; N--, i++) {
        for (int j = 1; j < N; j++)
            std::cout << " ";
        for (int j = 1; j < i; j++)
            std::cout << "0";
        
        std::cout << i % 10;
        
        for (int j = 1; j < i; j++)
            std::cout << "0";
        
        std::cout << "\n";
    }
}




/*
run:

        1
       020
      00300
     0004000
    000050000
   00000600000
  0000007000000
 000000080000000
00000000900000000

*/

 



answered Nov 17, 2022 by avibootz

Related questions

1 answer 94 views
1 answer 121 views
1 answer 119 views
1 answer 101 views
...