C++ Program to Check Armstrong Number














































C++ Program to Check Armstrong Number



#include <iostream>
#include <iterator>
#include <algorithm>
#include <cmath>

int main() {
	std::cout << "Enter Number: ";
	std::transform(std::istream_iterator<size_t>(std::cin),std::istream_iterator<size_t>(),
			std::ostream_iterator<std::string>(std::cout,"\n\nNumber:"),[](unsigned int num) {
			/*
			   * A positive integer is called an Armstrong number if
			   * a^n + b^n + c^n + d^n ... = abcd..
			*/
				unsigned int originalNumber = num;
				int n = 0;
				int result = 0;
				while (originalNumber != 0) {
					originalNumber /= 10;
					++n;
				}
				originalNumber = num;

				while(originalNumber != 0) {
					int reminder = originalNumber % 10;
					result += pow(reminder,n);
					originalNumber /= 10;
				}
				if (result == num)
					return "Is Armstrong number";
				else
					return "Is not Armstrong number";
			});
}

OUTPUT:

Enter Number: 371
Is Armstrong number

Number:1643
Is not Armstrong number


More Articles of Hatim Master:

Name Views Likes
Check if removing an edge can divide a Binary Tree in two halves 808 18
C++11 std::has_virtual_destructor 882 18
C++ program to find inorder successor in binary search tree using templates 1513 18
C++ future std::future::future (Constructor) 948 23
C++ Program to Merge Mails 818 21
C++ program for swapping two strings 630 19
C++ Program to count number of lines in a file 1013 23
C++ Progam for checking prime numbers 688 15
C++ std::atomic::load 1128 22
C++ Program to Find Hash of File 3406 11
C++ program to check if an array represents Inorder of Binary Search tree or not 610 19
C++ future std::future::wait_until 1424 19
C++ future std::future::valid 859 22
C++ program for merge sort 1067 18
C++ program to find median of binary search tree in O(n) using templates 730 19
C++11 std::genrate with std::array 766 17
C++ program to convert Binary to decimal,octal,hex 735 19
C++ Program to Check Vowel or Not 605 20
C++ std::find_first_of with vector 1044 20
C++ program to find if there is a triplet in a Balanced binary search tree that adds to zero 630 16
C++ Program to Find the Factorial of a Number 714 21
C++ Exception std::exception(Constructor) 908 13
C++ atomic std::atomic::fetch_and 818 20
Check if a Binary Tree contains duplicate subtrees of size 2 or more 1167 17
C++ Program to Print the Fibonacci sequence 702 13
C++ future std::async 1122 14
C++ program to check if a given binary tree is height balanced like a red-black tree 793 13
C++ program to insert an element into red black tree using template 2845 20
C++ program for Bubble sort using template 3041 13
C++11 std::genrate_n with std::vector 801 14
C++ program for copying string 535 11
C++ Program to Lowercase to Uppercase 686 15
C++ program to copy the content of the file 687 18
C++ program to count and display the number of lines not starting with the given alphabet in the file 1399 16
Finding Distance between two nodes 1072 12
C++ program for removing Punctuation 81 19
C++ program to find distance between two nodes of a binary search tree using templates 651 27
C++ program for solving Quadratic equation 789 26
C++ Program to Display Powers of 2 Using Anonymous Function 697 20
C++ program to add page at the beginning of the PDF 906 14
Print root to leaf paths without using recursion 793 26
C++ Program to Display Calendar 1348 29
C++11 std::genrate with std::forward_list 764 22
C++ std::find_if_not with std::deque 757 19
C++ program to query for ancestor-descendant relationship in a tree 847 13
C++ Program to Find ncR & nPr 884 21
Create loops of even and odd values in a binary tree 827 21
C++ atomic std::atomic::fetch_or 984 23
C++ program to convert kilometers to miles 729 27
C++ Program for comparing string 692 11
C++ Program to Find Factors of Number 636 24
C++ std::genrate with std::vector 773 14
C++ program to find vertical sum in binary tree 808 14
Program for shutdown or Restart PC. 761 20
C++ Program to Remove Words from Sentence 770 17
C++ program for Transpose matrix 777 22
C++ Constructor 911 20
C++ atomic std::atomic::compare_exchange_strong 855 16
Combining two sorted list and creating another sorted list 586 13
C++11 std::is_arithmetic 793 16
C++ program for adding matrices 710 20
C++ program to find check if given sorted sub-sequence exists in binary search tree 729 16
C++ Program to Convert Decimal to Binary, Octal and Hexadecimal 6002 22
C++ Program to Convert Fahrenheit to Celsius 754 21
C++ Program for finding size of string 654 24
C++ program to find a word in the file and print that line along with line number 1472 19
C++ program to reverse a path in binary search tree using queue using templates 975 12
C++ Program to Remove Spaces from String 775 21
C++ Program to Shuffle Deck of Cards 9497 18
C++ is_lock_free 734 16
C++ program to convert image/images to PDF 2637 24
C++ atomic std::atomic::compare_exchange_weak 855 19
C++ program for removing vowels from a string 818 25
C++ program for swapping two variable 640 18
Find Numbers Divisible by Number 1374 17
std::find_if_not with std::deque 754 18
C++ Program to Check Reverse equal Original 662 14
C++ program to count pairs from two binary search trees whose sum is equal to a given value x 581 14
C++ program for Insertion Sort 1309 18
C++ Program to Illustrate Different Set Operations 666 20
C++ Program to One Dimension Array Program 671 20
C++ program to count the number occurance of the given charactor in a file. 59 21
C++ program to print unique words 1706 16
C++11 std::is_abstract 736 26
C++ Program to Count the Number of Each Vowel 589 16
C++ program to find all the prime number in the given interval 617 26
C++ Program to Add Digits of Number 656 18
C++ Program to Print ASCII Values 655 15
Convert a Binary Tree into Doubly Linked List in spiral fashion 866 13
C++11 std::genrate with std::deque 687 20
C++ future std::future::get 999 21
C++ program to count the number of spaces present in a file. 678 19
C++ future std::future::share 873 18
C++ atomic std::atomic::fetch_xor 762 17
C++ program to check for identical binary serach trees without building the trees 550 13
C++ program to convert hexadecimal to binary,decimal,octal 841 22
C++ atomic std::atomic::operator-- 891 14
C++ program for multiplying matrices 615 27
C++ Program to append the file 831 24
C++ program for radix sort 1850 11
C++ program to read the content from a file, count and display the number of alphabets present in it. 609 26
std::find_first_of with std::deque 659 20
C++ program to construct ancestor matrix from a given binary tree using templates 618 15
C++ program to find list of files present in the directory 654 16
C++ std::atomic::store 1464 11
C++ program to find median of binary search tree 835 26
Print all root to leaf paths with there relative positions 742 24
Convert a tree to forest of even nodes 680 17
Convert a Binary Tree to a Circular Doubly Link List 661 16
Merge Two Binary Trees by doing Node Sum 832 23
C++ program to implement linux grep command. 2687 21
C++ Program to Check Leap Year 694 15
C++11 std::genrate_n with std::list 730 28
C++ atomic std::atomic::operator++ 930 23
C++ program to count the number of word in the file 1134 18
C++ Program for Counting sort 910 28
C++ program to get number of page of the pdf file 1400 19
C++ Program to Check Alphabet or Not 509 12
C++11 std::genrate_n with std::array 735 18
C++ future std::future::wait_for 1795 18
C++ program for concatenate String 756 28
std::find_if_not with std::array 816 26
std::find_if_not with std::vector 808 30
C++ Program to Uppercase to Lowercase 609 18
C++ Program to Count Word in Sentence 775 11
C++ program for Subtracting matrices 566 26
C++ Program to Make a Simple Calculator 615 17
Random Number 629 14
C++ program for checking the number is even or odd 765 27
std::find_if_not with std::list 725 28
C++ Program to convert octal to binary,decimal and hex 638 11
C++ program to encrypt a PDF file 1911 13
c++ program to get size of the file 613 15
C++ program to create a doubly linked list from a ternary tree 597 27
std::find_first_of with std::list 1104 20
C++ future std::future::wait 895 27
C++ Program to Display Fibonacci Sequence Using Recursion 675 16
C++ Program to Find Armstrong Number in an Interval 777 16
C++ program for Bucket Sort 4442 26
C++ std::genrate with std::list 602 18
C++ program to create a tree with left-child right-sibling representation using templates 1443 20
C++ program to shuffle words of each line of the given file 2244 21
C++ atomic std::atomic::fetch_add 1143 25
C++ program to find simple recursive solution to check whether binary search tree contains dead end using templates 558 15
C++ atomic_flag 889 13
Maximum spiral sum in Binary Tree 718 27
C++ atomic std::atomic::fetch_sub 804 18
C++ program to read content of multiple files and generate one output file 1015 22
C++ Program to print Pattern 632 22
C++ program to Decrypt a PDF File 1817 13
C++ Program to Merge Two Files 1923 19
C++ Program for reversing the String 583 24
C++ program to merge two files 780 14
Check if leaf traversal of two Binary Trees is same? 625 20
C++ program to get a page from PDF file 1166 19
C++ program for counting the character in the String 493 17
C++ Program to Check Armstrong Number 720 25
C++ program to check given array of size n can represent binary search tree of n levels or not 729 27
C++ Program to Sort Words in Alphabetic Order 704 24
C++11 std::alignment_of 710 13
C++ program to count the number of new lines present in a file. 715 16
C++ Program to Find HCF & LCM 712 20
C++ program to shuffle lines of the given file 721 12
C++ Program to Find the Size (Resolution) of a Image 2064 20
std::find_if_not with std::forward_list 723 23
C++ program to construct tree from ancestor matrix using templates 958 14
C++ std::atomic::exchange 802 19
std::find_fist_of with std::forward_list 655 15
C++11 std::extent 794 14
C++ program to merge PDF files 3191 22

Comments