Menu

Monday, August 9, 2010

C++ Reverse any 4 digit number code

#include
using namespace std;

void reverse(int num);
//this program allows you to reverse any 4 digit number entered by the user.
int main()
{

int num;
int digit1;
int digit2;
int predigit3;
int digit3;
int predigit4;
int digit4;
int ans;


cout << "This program will reverse any 4 digit number entered by the user. \n"; cout << "Enter the 4 digit number to be reversed. \n"; cin >> num;


void reverse(int num);
{

digit1 = num/1000;
digit2 = (num-(digit1*1000))/100;
predigit3 = num/100;
digit3 = (num-(predigit3*100))/10;
predigit4 = num/10;
digit4 = num-(predigit4*10);


ans=(digit4*1000)+(digit3*100)+(digit2*10)
+(digit1);
}

cout << "Your number reversed is = " << ans << "\n\n";

return 0;
}


comments:
This C++ is working fine :) We had C++ lab exercises in school :D
iceblue007's anime, manga, reviews, recommendations, blogs and lists at Anime-Planet
Anime-Planet.com - anime | manga | reviews