1234
2341
3421
4321
int main()
{
int i,j,k;
for(i=1;i<=4;i++)
{
k = i-1;
for(j=i;j<i+4;j++)
{
if(j<=4)
{
printf("%d",j);
}
else
{
printf("%d",k--);
}
}
printf("\n");
}
return 0;
}
Related Links:
- More Number Pattern Programs
- Star Pattern Programs in C
- Alphabet Pattern Programs in C
- Series Programs in C
there seems to be a mistake in the logic.Kindly check the pgm once again
ReplyDeleteThanks for pointing the issue, plz check it now :)
Deleteit works
Delete#include
int main()
{
int c;
int i,j;
int p=0;
int l;
for(i=1;i<=4;i++)
{
c = i;
for(j=1;j<=4-p;j++)
printf("%d",c++);
for(j=0;j<p;j++)
printf("%d",l--);
p++;
l = p;
printf("\n");
}
}
#include
ReplyDeletemain()
{
int i, j;
for (i=1; i<=4; ++i)
{
for (j=i; j<=4; ++j)
{
printf("%d", j);
}
for (j=0; j<i-1; ++j)
{
printf("%d", i-j-1);
}
printf("\n");
}
return 0;
}
i am not understand please explain briefly
ReplyDelete#include
ReplyDeletevoid main()
{
int i,j;
i=1;
while(i<=4)
{
j=i;
while(j<=4)
{
printf("%d\t",j);
j++;
}
j=i-1;
while(j>=1)
{
printf("%d\t",j);
j--;
}
printf("\n");
i++;
}
}
Much better logic
ReplyDelete#include
using namespace std;
int drawpattern(int *n)
{
for (int i=1;i<=*n;i++)
{ int k=i;
for(int j=1;j<=*n;j++)
{
if(k>*n)
{
cout<<" "<<(*n+1-j);
}
else
{
cout<<" "<>n;
drawpattern(&n);
return 0;
}
#include
ReplyDeleteint main()
{
int r,i,j;
printf("Enter the no. of rows : ");
scanf("%d",&r);
for(i=1;i<=r;i++)
{
for(j=i;j<=r;j++)
{
printf("%d",j);
}
for(j=i-1;j>=1;j--)
{
printf("%d",j);
}
printf("\n");
}
return 0;
}
The above program is wrong....
ReplyDelete