Don’t worry, unlock all articles / blogs on PrepInsta by just simply logging in on our website
Print Right Diamond Number Pattern Type4
September 23, 2021
PRINTING PATTERN:
3
44
555
6666
555
44
3
PREREQUISITE:
Basic knowledge of C language and use of loops.
ALGORITHM:
Take the number of rows as input from the user and store it in any variable.(‘r‘ in this case).
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
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++)
Inside this loop print i+3.
Else run a different loop from j=i to jThe loop should be structured as for( j=i ; j
Inside this loop print (r-i+2).
Inside the main loop print a newline to move to the next line after each row is printed.
#include
int main()
{
int rows,i,j=0,k=0,x=0;
printf(“enter the number of rows\n”);
scanf(“%d”,&rows);
for(i=1;i<=rows;i++)
{
j=0;
k=0;
if(i<=(rows+1)/2)
{
while(j(rows+1)/2)
{
while(k<(rows-i+1))
{
printf("%d",i-x);
k++;
}
x=x+2;
printf("\n");
}
}
return 0;
}