C++ do while loop

create a program that will accept a number and display it in reversed

Page 1 of 1

4 Replies - 3831 Views - Last Post: 16 February 2009 - 03:30 AM Rate Topic: -----

#1 mahaldita  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 09-February 09

C++ do while loop

Posted 09 February 2009 - 12:28 AM

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.
Is This A Good Question/Topic? 0
  • +

Replies To: C++ do while loop

#2 David W  Icon User is offline

  • DIC supporter
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,788
  • Joined: 20-September 08

Re: C++ do while loop

Posted 09 February 2009 - 03:51 AM

If you search through the

Quote

snippets
here at DIC

or look here ...

http://www.dreaminco...wtopic85415.htm

you may get a jump start ... this time :D

Shalom,
David
Was This Post Helpful? 1
  • +
  • -

#3 soroush  Icon User is offline

  • D.I.C Head

Reputation: -8
  • View blog
  • Posts: 67
  • Joined: 03-February 09

Re: C++ do while loop

Posted 10 February 2009 - 01:20 PM

View Postmahaldita, 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;
}


Was This Post Helpful? -1
  • +
  • -

#4 mahaldita  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 09-February 09

Re: C++ do while loop

Posted 16 February 2009 - 12:22 AM

View Postsoroush, on 10 Feb, 2009 - 12:20 PM, said:

View Postmahaldita, 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.:-)
Was This Post Helpful? 0
  • +
  • -

#5 David W  Icon User is offline

  • DIC supporter
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,788
  • Joined: 20-September 08

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

int reverseNum(int number)
{
    int rev = 0;
    while(number) /* exit when number is zero */
    {
        rev = rev*10 + number%10;
        number /= 10;
    }                
    return rev;
}

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1