1%2 - Modulus Question - C++ Forum
cplusplus.com
tappedout (3) I am getting differing opinions on the answer to 1%2. Some say you should round and the answer is 1 and some say the answer is 0 because modulus only deals with integer values in C++. I used a sample program to test this in the compiler and it seems to be rounding the answer because it says the value is 1. Anyone out there have insight and can help us settle this? .
Disch (13742) There is no rounding to be done. % gives you the remainder of integer division. 1%2 is 1 because 1 divided by 2 is 0 remainder 1. % can only be used with ?nonnegative? integer types. Pretty much it works like so: if: A / B = d A % B = r then: (d * B) + r = A
melkiy (131) a%b behaves like follows (i consider a and b to be greater than 0) : Compose a into a = k*b + rest, where k - the largets integer that can appear here. The rest is the answer (it will be strictly less than b and greater or equal 0). Last edited on Topic archived. No new replies allowed. Home page | Privacy policy© cplusplus.com, 2000-2025 - All rights reserved - v3.3.3Spotted an error? contact us
- TUTORIALS
- REFERENCE
- ARTICLES
- FORUM
C++
- Tutorials
- Reference
- Articles
- Forum
Forum
- Beginners
- Windows Programming
- UNIX/Linux Programming
- General C++ Programming
- Lounge
- Jobs
- Forum
- General C++ Programming
- 1%2 - Modulus Question
1%2 - Modulus Question
Từ khóa » C++ 1 2
-
C++ Why Does ((1 / 2) * 2) Return 0 [duplicate] - Stack Overflow
-
C++ : Calculate The Series (1) + (1+2) + … + (1+2+3+...+n)
-
C++ Basics - C++ Programming Tutorial
-
Is .5 Equal To 1/2 In The C Language? - Quora
-
Modulo Operator (%) In C/C++ With Examples - GeeksforGeeks
-
A Short Introduction To Computer Programming, Using C++
-
BASICs Of C/C++ Programming
-
10 Common Programming Mistakes In C++ 1 - UCR CS
-
C++ Program To Calculate Sum Of Natural Numbers - Programiz
-
4. Basic Declarations And Expressions - Practical C++ Programming ...
-
Plus One - LeetCode
-
1/2 Should Not Equal Zero - Musing Mortoray
-
C++ Program To Find Nth Term Of The Series 1, 1, 2, 6, 24…
-
[PDF] Some Practice Problems For The C++ Exam And Solutions For The ...