Q. Write a Number reverse program in C language as following pattern:
1 2 3 4
8 7 6 5
9 10 11 12
16 15 14 13
Ans.
/*c program for reverse number pattern rhombus*/
#include<stdio.h>
int main()
{
int r,c,p;
for(r=1; r<=4; r++)
{
if(r%2==0)
{
if(r==2)
{
for(c=1,p=8; c<=4; c++,p--)
printf(" %d", p);
}
else
{
for(c=1,p=16; c<=4; c++,p--)
printf(" %d", p);
}
}
else
{
if(r==1)
{
for(c=1; c<=4; c++)
printf(" %d", c);
}
else
{
for(c=1,p=9; c<=4; c++,p++)
printf(" %d", p);
}
}
printf("\n");
}
getch();
return 0;
}
You might also like to read:
1 2 3 4
8 7 6 5
9 10 11 12
16 15 14 13
Ans.
/*c program for reverse number pattern rhombus*/
#include<stdio.h>
int main()
{
int r,c,p;
for(r=1; r<=4; r++)
{
if(r%2==0)
{
if(r==2)
{
for(c=1,p=8; c<=4; c++,p--)
printf(" %d", p);
}
else
{
for(c=1,p=16; c<=4; c++,p--)
printf(" %d", p);
}
}
else
{
if(r==1)
{
for(c=1; c<=4; c++)
printf(" %d", c);
}
else
{
for(c=1,p=9; c<=4; c++,p++)
printf(" %d", p);
}
}
printf("\n");
}
getch();
return 0;
}
/*************************************************************
The output of above Continuous Rhombus Number Pattern program would be:
**********************************************************/
Figure: Screen shot for Continuous Rhombus Number Pattern C Program |
You might also like to read:
0 komentar:
Post a Comment