#include<stdio.h>
int main()
{
int i,j,n;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=n+1;j++)
{
if(i%2==0)
{
if(j==1)
{
printf(" %d",i+1);
}
else
printf(" %d",i);
}
else
{
if(j==n+1)
{
printf(" %d",i+1);
break;
}
else
{
printf(" %d",i);
}
}
}
printf("\n");
}
return 0;
}
input 7:
output:
1 1 1 1 1 1 1 2
3 2 2 2 2 2 2 2
3 3 3 3 3 3 3 4
5 4 4 4 4 4 4 4
5 5 5 5 5 5 5 6
7 6 6 6 6 6 6 6
7 7 7 7 7 7 7 8
int main()
{
int i,j,n;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=n+1;j++)
{
if(i%2==0)
{
if(j==1)
{
printf(" %d",i+1);
}
else
printf(" %d",i);
}
else
{
if(j==n+1)
{
printf(" %d",i+1);
break;
}
else
{
printf(" %d",i);
}
}
}
printf("\n");
}
return 0;
}
input 7:
output:
1 1 1 1 1 1 1 2
3 2 2 2 2 2 2 2
3 3 3 3 3 3 3 4
5 4 4 4 4 4 4 4
5 5 5 5 5 5 5 6
7 6 6 6 6 6 6 6
7 7 7 7 7 7 7 8
No comments:
Post a Comment