How Do i Do This In C++ ?:
Write A Program that prompts the user to input an integer and then outputs the number with the digits reversed . For example if the input is 12345 the output should be 54321 . also he program must output 5000 as 0005 and 980 as 089...
please help guys!
Reversing the input in C++ .. Help Please!?
#include %26lt;iostream%26gt;
using namespace std;
void main ()
{
int numberarray[5];
int temp = 5;
cout %26lt;%26lt; "Numbers: " %26lt;%26lt; endl;
for (int x = 0; x %26lt; 5; x++)
{
cin %26gt;%26gt; numberarray[x];
}
cout %26lt;%26lt; endl;
//For greatest to least
for (int i = 0; i %26lt; 5; i++)
{
for (int x = 0; x %26lt; 5; x++)
{
if (numberarray[x] %26lt; numberarray[i])
{
temp = numberarray[x];
numberarray[x] = numberarray[i];
numberarray[i] = temp;
}
}
}
for (int j = 0; j %26lt; 5; j++)
{
cout %26lt;%26lt; numberarray[j] %26lt;%26lt; endl;
}
cout %26lt;%26lt; endl;
//For least to greatest
for (int i = 0; i %26lt; 5; i++)
{
for (int x = 0; x %26lt; 5; x++)
{
if (numberarray[x] %26gt; numberarray[i])
{
temp = numberarray[x];
numberarray[x] = numberarray[i];
numberarray[i] = temp;
}
}
}
for (int j = 0; j %26lt; 5; j++)
{
cout %26lt;%26lt; numberarray[j] %26lt;%26lt; endl;
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment