1. ## help me out

i want a method too get the last two digit from a number

like 299 then i should get 99
or 178 then 78

plz if u know reply soon

2. er, not sure, but try this:

Code:
```#include <iostream>

using namespace std;

int number;

int main()
{

cout << "Please type in a three digit number: ";
cin >> number;

number=number- ;   // this part you would minus what ever the first figure was, ie: if it
//  was 150 then take away 100

cout << "You typed in " << number; // this would display your outcome
cin.get();
cin.ignore();
return 0;
}```
I wrote this in C++, but if you transfer it into C it should operate the same.

3. I'm sure the % operator would come in handy here

4. Subtraction is a pretty quick method though no?

Why not just keep on subtracting 100 while your number is greater than 100?

5. Originally Posted by Epo
Subtraction is a pretty quick method though no?

Why not just keep on subtracting 100 while your number is greater than 100?

yes, you can do it.. but its just complecating the matter..

Like salem said it..

take the number.. and do a modulo (%) 100.. so it will give you the reminder.. which is less than 100 i.e ..the last 2 digits.. !!

isn't it easy...

6. Originally Posted by Epo
Subtraction is a pretty quick method though no?

Why not just keep on subtracting 100 while your number is greater than 100?
O(1) is faster than O(N).

7. just use (variable)%100 to get last two digits.use type casting (int)variable.if ur variable is float.as told by others.got it my hindu brother?.

8. Code:
```#include <stdio.h>

int main(void) {
int n;
printf("\nEnter a number: ");
scanf("%i", &n);
printf("\nNumber: %i\n", n % 100);
return 0;
}```

9. O(1) is faster than O(N).
Depends on the size of N in this case, no?

Compared to one subtraction, one modulus is a fairly expensive computation.

I guess Modulus would be superior for small values of N, but only if there aren't many calculations. If the number stays in the 100s, but must be calculated for 100,000,000 numbers, I would say subtraction might be faster (I have no real data to work from here, but I might test it out just for fun).

For numbers that are big though, I would say no contest that Modulus wins (I.e. 100,890,324).

So yes, in most cases I would say modulus would be faster here, and yeah, I see it's the better choice. There is the once scenario though (which probably isn't what's happening), and, if nothing else, it's just another way to approach the problem.

10. You're not just dealing with subtraction though. You're dealing with a whole additional loop which means at least a while(n > 99) and that check takes time as well. You have to take all of that into account.

11. Very true, very true. I don't know the cost that would create, but MOD is definitely becoming superior by the second