Generate following output using for loops
1 2 3 4 5
10 9 8 7 6
11 12 13 14 15
20 19 18 17 16
#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,k=0,flag=0,t=1;
clrscr();
for(i=1; i<=4; i++)
{
if(i%2==0)
{
t=k=k+4;
flag=1;
}
else
{
k++;
flag=0;
}
if(flag==1)
{
for(j=1; j<=5; j++)
{
printf("%d ",t);
t--;
}
printf("\n");
}
else
{
for(j=1; j<=5; j++)
{
printf("%d ",k);
k++;
}
printf("\n");
}
}
getch();
return 0;
}
0 comments :
Post a Comment