WHAT IS ARMSTRONG NUMBER?

  • برمجة سي c

WHAT IS ARMSTRONG NUMBER?

Sum of a number’s digits raised to the power total number of digits is armstrong number.

Armstrong numbers example: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407, 1634 etc

Explanation:

3 = 3^1 = 3

153 = 1^3 + 5^3 + 3^3 = 15

Non-Armstrong numbers:

156 = 1^3 + 5^3 + 6^3 . This value is equal to 342. So, 156 is not an armstrong number

الأجوبة

#include <stdio.h>
 
int main()
 
{
 
   int n, sum = 0, t, remainder;
 
   printf("\nPlease enter a number to find whether it is an armstrong or not");
 
   scanf("%d",&n);
 
 
 
   t = n;
 
 
 
   while( t != 0 )
 
   {
 
      remainder = t%10;
 
      sum = sum + remainder*remainder*remainder;
 
      t = t/10;
 
   }
 
   if ( n == sum )
 
      printf("\nThe number %d is an armstrong number", n);
 
   else
 
      printf("\nThe number %d is not an armstrong number", n);
 
   return 0;
 
}

output:

Please enter a number to find whether it is an armstrong or not 3

The number 3 is not an armstrong number

هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...