Follow This Blog For more... 😊

C Program to print Number Diamond Pattern whole line with same number for n number of lines.[Pattern 19]| Using C language| C Program series 40|

👨‍💻C Program to 
print Number Diamond Pattern () whole line with the same number for n number of lines.[Pattern:19]

Code :

For n number of LINES:

   
   /*
    C Program to print Number Diamond Pattern whole line with same number for n number of lines.[Pattern 19]
    For Example:n=5
         
        1
        2 2
       3 3 3
      4 4 4 4
     5 5 5 5 5
      4 4 4 4
       3 3 3
        2 2
         1
   
    */
   
    #include<stdio.h>
    main()
    {
        printf("C Program to print Number Diamond Pattern whole line with same number for n number of lines.[Pattern 19]\n\n");
       
        int i,j,k,n;
       
        printf("Enter the ODD number of lines:");
        scanf("%d",&n);
       
        if(n%2==0)
        {
            n=n+1;
        }
        printf("Number Diamond Pattern for %d lines.\n",n);
        int half=n/2;
       
        for(i=1;i<=n;i++)
        {
            if(i<=half+1)
            {
                for(j=half+1-i;j>0;j--)
                {
                    printf(" ");
                }
                for(j=1;j<=i;j++)
                {
                    printf("%d ",i);
                }
            }
            else
            {
                for(j=1;j<=i-half-1;j++)
                {
                    printf(" ");
                }
                for(k=n-i+1;k>0;k--)
                {
                    printf("%d ",(n-i+1));
                }
            }
            printf("\n");
        }
    }

The output of Code:




👉Click for more C Program series Questions.[Questions list]

Comments

Popular Posts