bsc

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

pc-ip-16.c (979B)


      1 /*
      2  * Author  : Amit Dutta <amitdutta4255@gmail.com>
      3  * Date    : 05 Jan 2026
      4  * Repo    : https://github.com/notamitgamer/bsc
      5  * License : MIT License (See the LICENSE file for details)
      6  */
      7 
      8 /*
      9  * Question 16:
     10  * Write a C program that includes a user-defined function named isArmstrong with the signature int isArmstrong(int num);.
     11  */
     12 
     13 #include <stdio.h>
     14 #include <math.h>
     15 
     16 int isArmstrong(int);
     17 
     18 int main()
     19 {
     20     int num;
     21     printf("Enter the number: ");
     22     scanf("%d", &num);
     23     if (isArmstrong(num))
     24     {
     25         printf("\nInput %d is a Armstrong number.", num);
     26     }
     27     else
     28     {
     29         printf("\nInput %d is not a Armstrong number.", num);
     30     }
     31     return 0;
     32 }
     33 
     34 int isArmstrong(int num)
     35 {
     36     int temp = num;
     37     int power = 0;
     38     int result = 0;
     39     while (temp > 0)
     40     {
     41         power++;
     42         temp /= 10;
     43     }
     44     temp = num;
     45     while (temp > 0)
     46     {
     47         result += (int)pow((temp % 10), power);
     48         temp /= 10;
     49     }
     50     return result == num;
     51 }
© 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