# how to get the same repeating numbers for any of my imput number?

This topic is 1448 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have input numbers:

1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13.... etc

I would like to get output for each of these nunbers to be:

1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2... etc

so for my input 12 i wanna get 4 and for 13 it would be 1 and so on

is there any simple way how I could get that?

for example 13 - ( int(13/4) * 4 )  is 1

that works for 14 or 15 too, but unfortunately not for 12 or 16 as i will get 0 which is wrong

##### Share on other sites

You want the modulo operator, which essentially gives you the remainder of a division (although there are some subtle differences for negative numbers)

It might look like 'mod' or '%' depending on the language.

For your specific case, try: ((n - 1) % 4) + 1

Edited by C0lumbo

##### Share on other sites

Yes, Thank you C0lumbo!

Thats exactly what I needed..

I will never have a negative number so this is more than enough for me.

1. 1
2. 2
Rutin
18
3. 3
4. 4
5. 5

• 9
• 9
• 14
• 12
• 10
• ### Forum Statistics

• Total Topics
633271
• Total Posts
3011163
• ### Who's Online (See full list)

There are no registered users currently online

×