• Armstrong number is a number which order of n if
  • xyz=x n + y n + z n;
  • To check three digit Armstrong number in c programming
  • 153=13 * 53*33
  • In the same way we can also check four digit Armstrong number
  • 1634=14+64+34+44 is Armstrong  number.
  • Now let us check a four digit number is armstrong or not by using recursive function in c.
  • Armstrong number in c using recursion function.
  • Four digit armstrong number in c. check below program for four digit or n digit armstrong number in c programming.



Program #1: Write a c program to check four / 4 digit number or N digit number is armstrong number or not by using recursive function

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int powerfun(int, int);
  5.  
  6. int main()
  7. {
  8.    int n, sum = 0, temp, remainder, digits = 0;
  9.  
  10.    printf("Input number to check Armstrong or not");
  11.    scanf("%d", &n);
  12.  
  13.    temp = n;
  14.    // check the number of digits in given number
  15.    while (temp != 0) {
  16.       digits++;
  17.       temp = temp/10;
  18.    }
  19.  
  20.    temp = n;
  21.  
  22.    while (temp != 0) {
  23.       remainder = temp%10;
  24.       sum = sum + powerfun(remainder, digits);
  25.       temp = temp/10;
  26.    }
  27.  
  28.    if (n == sum)
  29.       printf("%d is an Armstrong number.\n", n);
  30.    else
  31.       printf("%d is not an Armstrong number.\n", n);
  32.  
  33.    getch();
  34. }
  35.  
  36. int powerfun(int num, int r) {
  37.    int c, res = 1;
  38.  
  39.    for (c = 1; c <= r; c++) 
  40.       res = res*num;
  41.  
  42.    return res;   
  43. }

Output:


armstrong number recusrion function c

Instance Of Java

We will help you in learning.Please leave your comments and suggestions in comment section. if you any doubts please use search box provided right side. Search there for answers thank you.
«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply

Select Menu