Home > Back-end >  Need to achieve the effect of: 1, 2, 3, 4, 5, 2, 3, 4, 5, 1, 3, 4, 5, 1 2 1 2 3 4 5 1 2 3 4
Need to achieve the effect of: 1, 2, 3, 4, 5, 2, 3, 4, 5, 1, 3, 4, 5, 1 2 1 2 3 4 5 1 2 3 4

Time:11-11

How to use the most simple for loop to achieve
The effect of the need to achieve:

1, 2, 3, 4, 5
2, 3, 4, 5 1
3 4 5 1 2
4 5 1 2 3
1 2 3 4 5
(can't use arrays)

CodePudding user response:

 
Int nCount=5;
For (int I=0; I & lt; NCount; + + I)
{
for (int j=0; J & lt; NCount; + + j)
{
Int nOutput=(I + j) % (nCount) + 1;
Printf (" % d ", nOutput);
}

Printf (" \ r \ n ");
}

CodePudding user response:

So:
 
#include

Int main ()
{
int i;
int j;
for (j=1; J<6; J++)
{
For (I=j; i{
If (I & lt; 6)
Printf (" % d ", I);
The else
Printf (" % d ", I % 5);
printf(" ");
}
printf("\n");
}
return 0;
}

CodePudding user response:

reference 1st floor Minikinfish response:
 
Int nCount=5;
For (int I=0; I & lt; NCount; + + I)
{
for (int j=0; J & lt; NCount; + + j)
{
Int nOutput=(I + j) % (nCount) + 1;
Printf (" % d ", nOutput);
}

Printf (" \ r \ n ");
}

Thank you, thank you very much, and don't thank gifts

CodePudding user response:

reference 1st floor Minikinfish response:
 
Int nCount=5;
For (int I=0; I & lt; NCount; + + I)
{
for (int j=0; J & lt; NCount; + + j)
{
Int nOutput=(I + j) % (nCount) + 1;
Printf (" % d ", nOutput);
}

Printf (" \ r \ n ");
}

Thank you, thank you