“Numer Armstrong” Kod odpowiedzi

Numer Armstrong

// C++ Program to find
// Nth Armstrong Number
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
 
// Function to find Nth Armstrong Number
int NthArmstrong(int n)
{
    int count = 0;
 
    // upper limit from integer
    for (int i = 1; i <= INT_MAX; i++) {
        int num = i, rem, digit = 0, sum = 0;
 
        // Copy the value for num in num
        num = i;
 
        // Find total digits in num
        digit = (int)log10(num) + 1;
 
        // Calculate sum of power of digits
        while (num > 0) {
            rem = num % 10;
            sum = sum + pow(rem, digit);
            num = num / 10;
        }
        // Check for Armstrong number
        if (i == sum)
            count++;
        if (count == n)
            return i;
    }
}
 
// Driver Function
int main()
{
    int n = 12;
    cout << NthArmstrong(n);
    return 0;
}
 
// This Code is Contributed by 'jaingyayak'
Anonymous

Numer Armstrong

// ARMSTRONG NUMBER
// 153

let sum = 0;
const number = 153;
// create a temporary variable
let temp = number;
while (temp > 0) {
  // finding the one's digit
  let remainder = temp % 10;

  sum += remainder * remainder * remainder;

  // removing last digit from the number
  temp = parseInt(temp / 10); // convert float into integer
}
// check the condition
if (sum == number) {
  console.log(`${number} is an Armstrong number`);
} else {
  console.log(`${number} is not an Armstrong number.`);
}
Abhishek

Odpowiedzi podobne do “Numer Armstrong”

Pytania podobne do “Numer Armstrong”

Więcej pokrewnych odpowiedzi na “Numer Armstrong” w JavaScript

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu