Remove leading zeroes

This is a discussion on Remove leading zeroes within the C++ Programming forums, part of the General Programming Boards category; I have a working code that takes a number and its square to check the reverse of the number and ...

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    12

    Remove leading zeroes

    I have a working code that takes a number and its square to check the reverse of the number and see if it matches a reverse of the original square.

    Code:
    #include<iostream>
    #include<conio.h>
    using namespace std;
    
    int reverse(int i)
    {
        int temp=i, sum=0;
        while(temp)
        {
            sum*=10;
            sum += temp%10;
            temp/=10;
        }
        return sum;
    }
    
    
    int square(int i)
    {
        return i*i;
    }
    
    
    void main()
    {
        for(int i=1; i<10001; i++)
        {
            if(i>9)
            {
                if(i!=reverse(i))
                {
                    if(square(reverse(i))==reverse(square(i)))
                    {
                        cout<<"The number "<<i<<" squares to "<<square(i)<<endl;
                        cout<<"The number "<<reverse(i)<<" squares to "<<square(reverse(i))<<endl;
                        cout<<endl;
                    }
                }
            }
        }
        getch();
    }
    An output answer that would be correct for example:

    The number 12 squares to 144
    The number 21 squares to 441

    However, I want to remove answers with leading zeroes that are included in the output, such like:

    The number 20 squares to 400
    The number 2 squares to 4

  2. #2
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,681
    First mind that a typical main is like
    Code:
    int main()
    {
         ....
         return 0;
    }
    Also i have to admit that i do not get what is the question.

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    2,041
    So if the number is devisible by 10, then skip it. That's !(i%10).
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pad leading zeroes for float in printf
    By Maroli5 in forum C Programming
    Replies: 3
    Last Post: 05-04-2011, 04:40 PM
  2. Remove leading zeros in a binary
    By Khalif in forum C Programming
    Replies: 3
    Last Post: 02-16-2010, 04:43 PM
  3. Removing zeroes from float
    By lollerpoller in forum C Programming
    Replies: 1
    Last Post: 05-14-2004, 03:33 AM
  4. Initilizing global array to all zeroes
    By Durafei in forum C++ Programming
    Replies: 3
    Last Post: 06-07-2003, 12:33 PM
  5. Remove leading spaces/tabs
    By ylph02 in forum C Programming
    Replies: 4
    Last Post: 06-07-2002, 03:45 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21