Sunday, September 13, 2015

Reverse a Number in a Text File in C++

This is another program that I wrote in C++ that will ask a series of integer number and then it will display the number in reverse order.

If you  have some questions please send me an email at jake.r.pomperada@gmail.comand jakerpomperada@yahoo.com. My mobile number here in the Philippines is 09173084360.

Program Listing


#include <iostream>
#include <fstream>

using namespace std;

main() {
      int number=0;
      int remainder=0;

       ofstream file("result.txt");

       cout << "\t Reverse a Number Version 1.0";
       cout << "\n\n";
       cout<<"\n Enter the number :=> ";
       cin>>number;

       cout<<"\n The number with reverse digits is  ";
  file << "\n ===== Reverse a Number 1.0 =====";
  file << "\n\n";
  file << "\n Original Number :=> " << number;
  file << "\n";
 file << "\n Reversed Number :=> ";
       do
 {
    remainder=number%10;

      cout<<remainder;

          file << remainder;

    number=number/10;
 } while(number>0);

  file.close();

  cout << "\n\n";
  system("pause");
  }

No comments:

Post a Comment