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,900 questions

51,831 answers

573 users

How to print a double pyramid pattern of numbers in C

1 Answer

0 votes
#include <stdio.h> 

int main(void)
{   
    int i,j,k,l,b,n;
    printf("How many numbers? ");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        for(l=0;l<i;l++)
            printf(" ");
        for(j=i+1;j<=n;j++)
            printf("%d",j);
        for(k=n-1;k>i;k--)
            printf("%d",k);
        printf("\n");
    }
    b=n-1;
    for(i=0;i<n-1;i++)
    {
        for(l=n-2;l>i;l--)
            printf(" ");
        for(j=b;j<=n;j++)
            printf("%d",j);
        for(k=n-1;k>=b;k--)
            printf("%d",k);
        printf("\n");
        b--;
    }
    return 0;
}


 
/*
run:
   
How many numbers? 5
123454321
 2345432
  34543
   454
    5
   454
  34543
 2345432
123454321

*/

 



answered Nov 3, 2016 by avibootz

Related questions

2 answers 261 views
1 answer 227 views
1 answer 266 views
1 answer 247 views
1 answer 110 views
1 answer 233 views
...