Amstrong Number

#include <iostream>
#include <conio.h>
using namespace std;

int help=0;//lebih baik gunakan constructor
int hasil=0;//lebih baik gunakan constructor

class Amstrong
{
      private :
              int reverse;
              int num;
              int temp;
             
      public :
             int input();
             int proses();
             int output();
};
      int Amstrong ::  input()
      {
          cout<<"Masukan nilai : ";
          cin>>num;
          reverse = num;
      }
      int Amstrong ::  proses()
      {
          while (num !=0)
          {
          temp = num % 10;
          hasil = (temp*temp*temp)+hasil;
          help = help * 10 + temp;
          num = num/10;
          }
      }
      int Amstrong :: output()
      {
          if (reverse == hasil)
          cout<<"The number is amstrong number";
          else
          cout<<"The number is not amstrong number";
      }
         
int main()
{
    Amstrong akses;
    akses.input();
    akses.proses();
    akses.output();
    getch();
}

No comments:

Post a Comment

Tutorial Lengkap Hosting Website Gratis Dengan Gambar

Hallo Guys.. sudah sangat lama sekali sejak terakhir kali saya melakukan posting di blogger ini... kalau saya tidak salah terakhir saya ...