473,395 Members | 2,436 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Modulus

I know that any number % 10 = zero.
Can any body give me the answer to C++ beginner?
what's result of:
2%500.
Thank you all.
Jul 18 '06 #1
6 16932
"Hardy &&&" <fa***@alphalink.com.auwrites:
I know that any number % 10 = zero.
Sure? Try out the following program:

#include <iostream>

int main()
{
std::cout << "1 % 10 == " << 1 % 10 << "\n";
return 0;
}
Can any body give me the answer to C++ beginner?
what's result of:
2%500.
You can get an idea by trying out the following program.

#include <iostream>

int main()
{
std::cout << "2 % 500 == " << 2 % 500 << "\n";
return 0;
}
Best wishes
--
Marco Wahl
http://visenso.com
Jul 18 '06 #2
Hardy &&& wrote:
I know that any number % 10 = zero.
% operator gives remainder, so N % 10 != 0 always unless N is a
multiple of 10.
Can any body give me the answer to C++ beginner?
what's result of:
2%500.
cout << "2%500=" << 2%500 << endl;

-
SJ

Jul 18 '06 #3
"Hardy &&&" writes:
>I know that any number % 10 = zero.
Can any body give me the answer to C++ beginner?
what's result of:
2%500.
n mod 10 is not zero, contrary to what you thought.

As long as n and m are both positive, as in n % m, C obeys the rules
described in Wikipedia.

http://en.wikipedia.org/wiki/Modulo_operation
Jul 18 '06 #4
Hardy &&& posted:
I know that any number % 10 = zero.

And I know that the sky is green.

Can any body give me the answer to C++ beginner?
what's result of:
2%500.

(1) Divide 2 by 500, and round your answer down to the nearest integer.

(2) Take that integer, and multiply it by 500.

(3) Subtract the result from 2.
That's your answer.
--

Frederick Gotham
Jul 18 '06 #5
Hardy &&& wrote:
I know that any number % 10 = zero.
Can any body give me the answer to C++ beginner?
what's result of:
2%500.
Thank you all.

No it's not. For any positive n, n % 10 == 0 if n is a multiple of 10,
n/10 + r otherwise (r is the remainder and / is integer division). For 0
< n < 10 the remainder is simply n and for n == 0 the answer is 0 since
0/n == 0 for any n != 0. So 2 % 500 == 2. What's the problem?
Jul 18 '06 #6
Hardy &&& schrieb:
I know that any number % 10 = zero.
I don't think that this is right. Modulo returns the remainder of
any number / 10.

For example : 19 % 10 = 9

Check wikipedia for some more math ;)
Can any body give me the answer to C++ beginner?
what's result of:
2%500.
Thank you all.

Ciao,
Marco
Jul 19 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Chris Watson | last post by:
I'm trying to eliminate some warnings I'm getting -- probably not necessary but it's my final project: I have to use modulus so my variables are int. Is there some way to divide two results and...
2
by: Jim Hunter | last post by:
Hello all, I have been reading K&R2, and it says that "the sign of the result for % machine-dependent for negative operands." Does this mean that the absolute value of the result is...
3
by: exquisitus | last post by:
I'm trying to decide which of these two to use to calculate the remainder between two floating point numbers. My gut instinct says to go for the % operator - but I'm not sure if I am right. Which...
4
by: August Karlstrom | last post by:
Hi, How come the modulus operator doesn't always yield non-negative values? I expect e.g. (-1) % 3 to be 2 but I get -1. If I want to decrement a cyclic variable n by k I have to write something...
10
by: jantod | last post by:
I think there might be something wrong with the implementation of modulus. Negative float values close to 0.0 break the identity "0 <= abs(a % b) < abs(b)". print 0.0 % 2.0 # => 0.0 print...
5
by: Peter Pippinger | last post by:
Hello NG, i need to calculate the modulus with double precisson typed variables. this works well with integers: w1 = w1 % 360; but what do i have to do if i want to use w1 as double? ...
1
by: =?Utf-8?B?a3dfdWg5Nw==?= | last post by:
Hello Everyone I have a piece of code I was trying to convert over to VB.Net. I hoping someone can help me out. I have a sub routine or function that creates a SQL query string, creates a...
1
by: anitha18 | last post by:
hw to find modulus of a number in c++
0
by: zephyrus360 | last post by:
This is about a technique to find the mod of a very large integer with a normal small integer. I recently encountered this problem when I needed to compute the modulus of a very large number with...
4
by: tvnaidu | last post by:
How to calculate Prescalar and Modulus values for PIT (Programmable Interrupt Timer). I have microcontroller running at 60MHz. I am thinking of writing 1 milli sec ISR for PIT. I need to calculate...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.