write a c program to print pattern

1 2 3
8 9 4
7 6 5

Recommended Answers

All 2 Replies

int x,y,x1,y1,i;
x1=y1=x=y=0;
i=1;
int ar[3][3];
clrscr();
while(i<9)
	{
	while(x<2-x1){ar[y][x++]=i++;}
	while(y<2-y1){ar[y++][x]=i++;}
	while(x>x1){ar[y][x--]=i++;}x1++;
	while(y>y1){ar[y--][x]=i++;}y1++;
	ar[1][1]=9;
	x++;y++;
	}

Check it out

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.