How do I remove the first number from an integer?

后端 未结 3 968
悲&欢浪女
悲&欢浪女 2021-01-19 05:13

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

3条回答
  •  误落风尘
    2021-01-19 05:59

    I will probably attract the downvoters but here is what I would do:

    #include 
    #include 
    
    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

提交回复
热议问题