bsc

Comprehensive codebase and cou...
Log | Files | Refs | README | LICENSE

IP-16.c (1327B)


      1 /*
      2  * Author  : Amit Dutta <amitdutta4255@gmail.com>
      3  * Date    : 03 Jan 2026
      4  * Repo    : https://github.com/notamitgamer/bsc
      5  * License : MIT License (See the LICENSE file for details)
      6  */
      7 
      8 /* Write a C program that includes a user-defined function named isArmstrong with the 
      9 signature int isArmstrong(int num);. An Armstrong number is a number that is equal to 
     10 the sum of its own digits each raised to the power of the number of digits. For example, 
     11 153 is an Armstrong number because 1^3 + 5^3 + 3^3 = 153 */
     12 
     13 #include <stdio.h>
     14 #include <math.h>
     15 
     16 int isArmstrong(int);
     17 int count(int);
     18 
     19 int main()
     20 {
     21     int n;
     22     printf("Enter the number: ");
     23     scanf("%d", &n);
     24 
     25     if (isArmstrong(n))
     26     {
     27         printf("\nInput %d is a Armstrong Number.", n);
     28     }
     29     else
     30     {
     31         printf("\nInput %d is Not a Armstrong Number.", n);
     32     }
     33 
     34     return 0;
     35 }
     36 
     37 int count(int n)
     38 {
     39     int count = 0;
     40     while (n > 0)
     41     {
     42         count++;
     43         n = n / 10;
     44     }
     45     return count;
     46 }
     47 
     48 int isArmstrong(int n)
     49 {
     50     if (n < 0)
     51         return 0; 
     52     if (n == 0)
     53         return 1;
     54 
     55     int power = count(n);
     56     int temp = n;
     57     int checker = 0;
     58 
     59     while (temp > 0)
     60     {
     61         int digit = temp % 10;
     62         checker = checker + (int)round(pow(digit, power));
     63         temp = temp / 10;
     64     }
     65     return n == checker;
     66 }
© notamitgamer • Site Built: 2026-07-21 13:58:23 UTC • git-mirror commit: 1037f62 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror