Print Right Diamond Number Pattern Type4

PRINTING PATTERN:

3

44

555

6666

555

44

3

PREREQUISITE:

Basic knowledge of C language and use of loops.

ALGORITHM:

  1. Take the number of rows as input from the user and store it in any variable.(‘r‘ in this case).
  2. Run a loop ‘r’ number of times to iterate through each of the rows. From i=0 to i<r. The loop should be structured as for( i=0 ; i
  3. Use an if condition to to print the top half of the pyramid. if (i<=r/2). Then run a loop from j=0 to j<=i. The loop should be structured as for(j=0 ; j<=i ; j++)
  4. Inside this loop print i+3.
  5. Else run a different loop from j=i to jThe loop should be structured as for( j=i ; j
  6. Inside this loop print (r-i+2).
  7. Inside the main loop print a newline to move to the next line after each row is printed.

CODE IN C:

Code

#include
int main()
{
//declaring integer variables i,j for loops and r for number of rows int i,j,r;
//Asking user for input printf("Enter the number of rows(odd) :\n"); scanf("%d",&r); //taking number of rows and saving it in variable r for(i=0;i<r;i++) // loop for number of rows { if(i<=(r/2)) //if condition to print the top half { for(j=0;j<=i;j++) // loop for digits per each row { printf("%d",i+3); //printing numbers } } else //else condition to print the bottom half { for(j=i;j<r;j++) //loop for printing numbers { printf("%d",r-i+2); //printing numbers } } printf("\n"); // printing newline after each row } }

TAKING INPUT:

DISPLAYING OUTPUT:

If you want to do the same code but by doing 2 inputs then the code will change as –

Input:
              3  4
Output:
               3
              44
              555
              6666
              555
              44
              3

Input :
              4  4
Output:
              4
              55
              666
              7777
              666
              55
              4

Code 1

#include 
int main()
{
int i,j,s,N,count=0;
scanf(“%d%d”,&s,&N);
for(i=s;count<4;count++)
{
for(j=0;j<count+1;j++)
printf(“%d”,i);
printf(“\n”);
i=i+1;
}
for(i=s+N-2;count>0;count–)
{
for(j=0;j<count-1;j++)
printf(“%d”,i);
printf(“\n”);
i=i-1;
}
return 0;
}