Hello all, I hadn't touched a bit of programing until the start of this semester and it feels as if I've been thrown to the wolves. I am required to write a program that takes UP TO 5 digits, reverses it, and calculate the square roots of both. The code that I have thus far is;(adsbygoogle = window.adsbygoogle || []).push({});

#include<iostream> //required for cin, cout

#include<cmath>

using namespace std;

int main()

{

int n1,n2,n3,n4,n5,num;

cout<< "Please enter an integer, up to 5 digits in length" <<endl<<endl;

cin>>num;

cout<< "The Square root is:"<<sqrt(num)<<endl<<endl;

n5=num/10000; //

n4=(num%10000)/1000; //

n3=((num%10000)%1000)/100; //

n2=(((num%10000)%1000)%100)/10; //

n1=((((num%10000)%1000)%100)%10)/1; //

int num2=((n1*10000)+(n2*1000)+(n3*100)+(n4*10)+(n5*1)); // to declare second intiger

cout<< "The number in reverse is:" <<num2<<endl;

cout<< "The square root is:" <<sqrt(num2)<<endl;

system("pause");

return 0;

}

My only problem is with numbers that are less than 5 digits in length, when I have a number such as 234 when it reverses it the output sees it as 43200. How do I eliminate the trailing zeros so it wont throw off the square root of the reversed number.

Thanks,

Z

**Physics Forums | Science Articles, Homework Help, Discussion**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# New to C++; reversing a number upto 5 digits in length

**Physics Forums | Science Articles, Homework Help, Discussion**