I need to intake a number like: 200939915
After doing this, which I know how, I need to remove the first number so it becomes: 00939915
What is the best way
char *c = "200939915";
char *d = c + 1;
I will probably attract the downvoters but here is what I would do:
#include <iostream>
#include <math.h>
int main()
{
int number;
std::cin >> number;
int temp = number;
int digits = 0;
int lastnumber = 0;
while(temp!=0)
{
digits++;
lastnumber = temp % 10;
temp = temp/10;
}
number = number % (lastnumber * (int)pow(10,digits-1));
std::cout << number << std::endl;
return 0;
}
obviously since you want it in c change std::cin
to scanf
(or whatever) and std::cout
to printf
(or whatever). Keep in mind though that if you want the two 00 to remain in the left side of the number, Kane's answer is what you should do. Cheers
An alternative method, although I like Matt Kane's best:
unsigned long n = 42424242;
n = n % (unsigned long)pow(10.0, (double)floor(log10(n)));
// n = 2424242;