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

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,089 questions

40,774 answers

573 users

How to print a double pyramid pattern of numbers in C

Learn & Practice SQL


76 views
asked Nov 3, 2016 by avibootz
edited Jun 5, 2017 by avibootz

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 101 views
1 answer 87 views
1 answer 92 views
1 answer 79 views
1 answer 45 views
...