*C Program to check whether number is divisible by 11 and 9 or not*

Write a C Program to check whether number is divisible by 11 and 9 or not by recursion. Here’s simple Program that tests whether a number is divisible by 11 and 9 or not using Recursion in C Programming Language.

**Recursion : :**

**Recursion : :**

- Recursion is the process of repeating items in a self-similar way. In programming languages, if a program allows you to call a function inside the same function, then it is called a
of the function.**recursive call**

- The C programming language supports recursion, i.e., a function to call itself. But while using recursion, programmers need to be careful to define an exit condition from the function, otherwise it will go into an infinite loop.

- Recursive functions are very useful to solve many mathematical problems, such as calculating the factorial of a number, generating Fibonacci series, etc.

Below is the source code for C Program to check number is divisible by 11 and 9 using recursion which is successfully compiled and run on Windows System to produce desired output as shown below :

**SOURCE CODE : :**

**SOURCE CODE : :**

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
/* Program that tests whether a number is divisible by 11 and 9 or not */ #include<stdio.h> int divisibleBy9(long int x); int divisibleBy11(long int x); int main( ) { long int num; printf("Enter the number to be tested : "); scanf("%ld", &num); if(divisibleBy9(num)) printf("\nThe number is divisible by 9\n"); else printf("\nThe number is not divisible by 9\n"); if(divisibleBy11(num)) printf("\nThe number is divisible by 11\n"); else printf("\nThe number is not divisible by 11\n"); return 0; }/*End of main()*/ int divisibleBy9( long int n ) { int sumofDigits; if(n==9) return 1; if(n<9) return 0; sumofDigits=0; while(n>0) { sumofDigits += n%10; n/=10; } divisibleBy9(sumofDigits); }/*End of divisibleBy9()*/ int divisibleBy11( long int n ) { int s1=0, s2=0,diff; if(n == 0) return 1; if(n < 10) return 0; while(n>0) { s1 += n%10; n /=10; s2 += n%10; n /= 10; } diff = s1>s2 ? (s1-s2) : (s2-s1); divisibleBy11(diff); }/*End of divisibleBy11()*/ |

**OUTPUT : :**

**OUTPUT : :**

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
***************OUTPUT*************** ***************FIRST RUN************ Enter the number to be tested : 6534 The number is divisible by 9 The number is divisible by 11 ***************SECOND RUN************ Enter the number to be tested : 657 The number is divisible by 9 The number is not divisible by 11 ***************THIRD RUN************ Enter the number to be tested : 742 The number is not divisible by 9 The number is not divisible by 11 |

If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may * Contact Us* through our contact Page or you can also comment below in the comment section.We will try our best to reach upto you in the short interval.

**Thanks for reading the post….**