Sign in to follow this  

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

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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 this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this