Can anyone tell me how to use the % function?
ok i need to have the last number in a decimal number to be put in a nother variable:
will that store the last number in variable "num" (which is an integer) in variable "A"?Code:num % 10 = A
Thanks
This is a discussion on Num % 10 within the C++ Programming forums, part of the General Programming Boards category; Can anyone tell me how to use the % function? ok i need to have the last number in a ...
Can anyone tell me how to use the % function?
ok i need to have the last number in a decimal number to be put in a nother variable:
will that store the last number in variable "num" (which is an integer) in variable "A"?Code:num % 10 = A
Thanks
Talitore - Using DEV-C++
The % is called the modulus operator. A % B means what is the remainder if A were divided by B.
Any integer modulus 10 will tell you what the last digit in the integer is so:Code:7 % 5 = 2 // means 7 divided by 5 has a remainder of 2 10 % 5 = 0 // means 10 divided by 5 has a remainder of 0
So the answer to your question is yes, it WILL store the last digit into the variable "num".Code:159 % 10 = 9 2912381 % 10 = 1
it will store it into variable "num" or "A"
i asked if it would save it into "A"
thanks
Talitore - Using DEV-C++
num % 10 = A
Will give you a syntax error.
make that:
A = num % 10
The last digit of num will be stored in A.
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
Oops, you're right, I meant it would store it into A, but only if you type it like "A=num%10" like Magos said.
Thanks for all your help!