mardi 16 février 2021

we have to print a pattern in c using if else method [closed]

I HAVE GIVEN A CODE MAKE CHANGES IN IT TO PRINT THE PYRAMID PATTERN 1 121 12321 1234321 PLEASE TRY TO SPECIFY MY MISTAKE (USE C LANGUAGE ONLY) ANSWER THIS QUESTION USING IF ELSE METHOD AND REVIEW THE CODE

#include<stdio.h>
int main(int argc, char const *argv[])
{
 int n,i,j,k=1;
 scanf("%d",&n);
 for ( i = 0; i < n; i++)
 {    
     for ( j = 0; j <2*n+2; j++)
     {
         if (j>=n+1-i && j<=n+1+i)
         {
             if (j<n+1)
                {
                   printf("%d",k);
                   k++;
                }
            else if (j>n+1)
            {
                 k--;
                 printf("%d",k); 
                
            }
            
             else
             {
                
                 printf(" ");
             }
             
         }
         else
         {
              printf(" ");
         }
     }
     printf("\n"); 
 }
 
    
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire