Solved

Array

Posted on 2004-04-09
8
243 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 50 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
logging Access violation 6 21
Pointer in one class to member in another 6 128
What is sub-make ? 2 88
Setting variables in a stored procedure 5 52
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
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 how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

730 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