Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Array

Posted on 2004-04-09
8
Medium Priority
?
246 Views
Last Modified: 2010-04-15
What does data [5*i%6] equal?  When i equals 0, 1, 2, 3, 4, 5, and so on...

I'm somewhat confused on how the % works.
0
Comment
Question by:GJMill79
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 3

Accepted Solution

by:
idt earned 200 total points
ID: 10795180
% is the modulus operator..

or simply
(5 times i) divided by 6 has a remained of what?

5 % 2 is 1

Daniel
0
 
LVL 3

Expert Comment

by:idt
ID: 10795206
#include <iostream>
int main (void) {
  for(int i=1;i<12;i++)
    std::cout << "5 * " << i << " % 6 = " << (5*i%6) << std::endl;
  return 0;
}

5 * 1 % 6 = 5
5 * 2 % 6 = 4
5 * 3 % 6 = 3
5 * 4 % 6 = 2
5 * 5 % 6 = 1
5 * 6 % 6 = 0
5 * 7 % 6 = 5
5 * 8 % 6 = 4
5 * 9 % 6 = 3
5 * 10 % 6 = 2
5 * 11 % 6 = 1

Daniel
0
 

Author Comment

by:GJMill79
ID: 10795224
I'm confused...so (5 x 1)/6   ? = 1 ???  
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:GJMill79
ID: 10795226
Nevermind...I see it...it's 6/(5x1)
0
 

Author Comment

by:GJMill79
ID: 10795227
Thank you!
0
 

Author Comment

by:GJMill79
ID: 10795241
Actually I didn't calculate that right...can you explain that again?  how does work?
5 * 1 % 6 = 5
5 * 2 % 6 = 4
5 * 3 % 6 = 3
5 * 4 % 6 = 2
5 * 5 % 6 = 1
5 * 6 % 6 = 0
5 * 7 % 6 = 5
5 * 8 % 6 = 4
5 * 9 % 6 = 3
5 * 10 % 6 = 2
5 * 11 % 6 = 1
0
 
LVL 3

Expert Comment

by:idt
ID: 10795476
In the above posted results:

5 * 1 % 6 = 5  // in this case there was not a Proper Divisor, since 6 divided into 5, 0 times with 5 remainder
5 * 2 % 6 = 4
5 * 3 % 6 = 3
5 * 4 % 6 = 2
5 * 5 % 6 = 1  // in this case there was not a Proper Divisor, since 6 divided into 25, 4 times with 1 remainder
5 * 6 % 6 = 0  // in this case there was a Proper Divisor, since 6 divided into 30 exactly 5 times with no remainder (0).
5 * 7 % 6 = 5  // in this case there was not a Proper Divisor, since 6 divided into 35, 5 times with 5 remainder
5 * 8 % 6 = 4
5 * 9 % 6 = 3
5 * 10 % 6 = 2
5 * 11 % 6 = 1

(5 * 11) = 55
55 / 6 = 9.1666666666667
but since these are integers and not floats the quotiant would be 9.
(5 * 11) - ( 9 * 6) = 1 remaining, the result of the Modulus  operator.

The code that you have ensures that you can never attempt to reference an array element that is not 0,1,2,3,4 or 5.

Daniel
0
 

Author Comment

by:GJMill79
ID: 10795533
Thanks again!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question