C Programming
Computer Programming

Program in C to display the diagonal number pattern



Write a Program in c to display the following Pattern :


1                              1
    2                     2
          3         3
                4
          3         3
    2                     2
1                              1

\* C Program to display the diagonal number pattern *\

# include < stdio.h >
int   main( )
{

int   i, j, n, k=1 ;
printf(" Enter the Maximum Number : ") ;
scanf("%d ", & n) ;
printf("\n Pattern are : \n\n") ;
for (  i = 1 ; i <= (2 * n ) - 1 ; i++ )
{

for (  j = 1 ; j <= ( 2 * n )- 1 ; j++ )
{

if (   i == j || i + j == 2 * n  )
printf("   %d " ,  k) ;
else
printf("     ") ;

}
if (   i < n  )
k++ ;
else
k-- ;
printf(" \n ") ;

}
return ( 0 );

}

Output of Program :

Output of Program in C to diagonal number pattern