C++ Amstrong

#include<iostream>
#include<cstdlib>

using namespace std;

int main () {

    int a,b,n;

cout << "Input a number: / Bir sayı giriniz :";
    cin >> n;                    

    a = b = n;

    float digit = 0.0;                    
    double sum = 0;

    while(n >= 1)                
    {                                    
       n = (n / 10);       //  Basamak sayısını bulma.
        digit++;                        
    }                                    

    while(a >= 1)              
    {                                    
        n = a % 10;        //  Rakamaları ve rakamların üssünü alama.
        sum = sum + pow(n,digit);
        a = a/ 10;    
    }                                    

    if(sum == b)
    {
        cout << b <<" is an Armstrong Number."<    }
    else
    {
        cout << b << " is NOT an Armstrong Number."<    }

   
                 
    system("pause");
return 0;

 
}

Hiç yorum yok:

Yorum Gönder

make a commet to understand