Solved

Array

Posted on 2004-04-09
8
242 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
  • 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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Statment to match two tables in c# 6 80
Convert image to byte array 8 208
chcp 65001 File encoding 66 267
NEED HELP WITH VISUAL STUDIO 2017 (beginner) 6 65
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
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 and use conditional statements 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.

791 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