C program to print the following Pattern

Output:

 
3                                                                                                                                              
33333                                                                                                                                          
32223                                                                                                                                          
32123                                                                                                                                          
32223                                                                                                                                          
33333  

5                                                                                                                                                
555555555                                                                                                                                        
544444445                                                                                                                                        
543333345                                                                                                                                        
543222345                                                                                                                                        
543212345                                                                                                                                        
543222345                                                                                                                                        
543333345                                                                                                                                        
544444445                                                                                                                                        
555555555

Program:

#include<stdio.h>
#include<math.h>
int main()
{
    int n;
    scanf("%d",&n);
    int i,j;
    for(i=-(n-1);i<=(n-1);i++)
    {
        for(j=-(n-1);j<=(n-1);j++)
        {
            int val=(abs(i)>abs(j))?abs(i):abs(j);
            val++;
            printf("%d",val);
        }
        printf("\n");
    }
}

Comments

Popular posts from this blog

c++ program to print string along the diagonals of the matrix.

Kollywood Game