create a program that will accept a number and display it in reversed form.Make an equation to come up the best output..using do while loop.
C++ do while loopcreate a program that will accept a number and display it in reversed
Page 1 of 1
4 Replies - 2657 Views - Last Post: 16 February 2009 - 03:30 AM
Replies To: C++ do while loop
#2
Re: C++ do while loop
Posted 09 February 2009 - 03:51 AM
If you search through the here at DIC
or look here ...
http://www.dreaminco...wtopic85415.htm
you may get a jump start ... this time
Shalom,
David
Quote
snippets
or look here ...
http://www.dreaminco...wtopic85415.htm
you may get a jump start ... this time
Shalom,
David
#3
Re: C++ do while loop
Posted 10 February 2009 - 01:20 PM
mahaldita, on 8 Feb, 2009 - 11:28 PM, said:
create a program that will accept a number and display it in reversed form.Make an equation to come up the best output..using do while loop.
here it is!
#include<iostream>
using namespace std;
int main()
{
int i =0;
int arr[5];
cout<<"Please input 5 integers:"<<endl;
do
{
cin>>arr[i];
i=i+1;
}while(i<5);
cout<<"In reverse order: "<<endl;
i = 4;
do
{cout<<arr[i]<<endl;
i=i-1;
}while(i>=0);
system("pause");
return 0;
}
#4
Re: C++ do while loop
Posted 16 February 2009 - 12:22 AM
soroush, on 10 Feb, 2009 - 12:20 PM, said:
mahaldita, on 8 Feb, 2009 - 11:28 PM, said:
create a program that will accept a number and display it in reversed form.Make an equation to come up the best output..using do while loop.
here it is!
#include<iostream>
using namespace std;
int main()
{
int i =0;
int arr[5];
cout<<"Please input 5 integers:"<<endl;
do
{
cin>>arr[i];
i=i+1;
}while(i<5);
cout<<"In reverse order: "<<endl;
i = 4;
do
{cout<<arr[i]<<endl;
i=i-1;
}while(i>=0);
system("pause");
return 0;
}
thanks sorous...this will be a great help.:-)
#5
Re: C++ do while loop
Posted 16 February 2009 - 03:30 AM
... but if you want to reverse the order of digits in one number ... try the following ...
Shalom,
David
Shalom,
David
int reverseNum(int number)
{
int rev = 0;
while(number) /* exit when number is zero */
{
rev = rev*10 + number%10;
number /= 10;
}
return rev;
}
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote



|