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 <stdio.h>

int main(void)
{
    int N = 9;

    for (int i = 1; N > 0; N--, i++) {
        for (int j = 1; j < N; j++)
            printf(" ");
        for (int j = 1; j < i; j++)
            printf("0");

        printf("%d", i % 10);

        for (int j = 1; j < i; j++)
            printf("0");

        printf("\n");
    }

    return 0;
}



/*
run:

        1
       020
      00300
     0004000
    000050000
   00000600000
  0000007000000
 000000080000000
00000000900000000

*/

 



answered Nov 17, 2022 by avibootz

Related questions

1 answer 126 views
1 answer 129 views
1 answer 154 views
154 views asked Oct 16, 2019 by avibootz
...