bsc

Comprehensive codebase and coursework for the 4-year B.Sc. Computer Science Honours degree (WBSU)

git clone https://github.com/notamitgamer/bsc.git
· rebuilt hourlyOpen on GitHub
root / semester_1 / practice-c / pc007.c

pc007.c (724B)


      1 /* Armstrong number check only for three digit */
      2 
      3 #include <stdio.h>
      4 
      5 int main()
      6 {
      7     int num, temp1, armstrongCheck = 0;
      8     printf("Enter a three digit number : ");
      9     if (scanf("%d", &num) != 1)
     10     {
     11         printf("\nOnly positive number allowed.");
     12         return 1;
     13     }
     14     if (num < 100 || num > 999)
     15     {
     16         printf("\nOnly Three digit postive number allowed.");
     17         return 1;
     18     }
     19     temp1 = num;
     20     while (temp1 > 0)
     21     {
     22         armstrongCheck += (temp1 % 10) * (temp1 % 10) * (temp1 % 10);
     23         temp1 /= 10;
     24     }
     25     if (armstrongCheck == num)
     26         printf("\nInput %d is a armstrong number.", num);
     27     else
     28         printf("\nInput %d is not a armstrong number.", num);
     29     return 0;
     30 }