Ad Code

NEW POST

6/recent/ticker-posts

how to print 0,22,000,4444


concept:
 first we have to print spaces which is supposed to be run in the opposite direction so, let run a loop for row(i) in body of i run loop for j .
for printing spaces, we have to run opposite loops so we can use 4-i . we use this because we have to run this loop opposite means in the sense ****,***,**,*. 
if we do not use this concept the loop will print *,**,***,****

below is the code (runs on turbo c++)

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
for(i=1;i<=4;i++)
{
for(j=1;j<=4-i;j++)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
if(i%2==0)
{
printf("%d ",i);
}
else
{
printf("0 ");
}

}
printf("\n");
}
getch();
}





...

Post a Comment

0 Comments