Monday, July 8, 2019

number divisible by 11 or not in the c programming

#include <stdio.h>
#include <stdlib.h>

void test (long int x);
main ( )
{
    long int num;
    printf("Enter the numher to be tested ");
    scanf("%ld",&num);
    test(num) ;
}
void test(long int n)
{
    int s1=0, s2=0, k;
    while(n>0)
    {
        s1+=n%10;
        n/=10;
        s2+=n%10;
        n/=10;
    }
    k=s1>s2? (s1-s2) : (s2-s1) ;
    if(k>10)
        test(k);
    else if(k==0)
        printf ("The number is divisible by 11 \n") ;
    else
        printf("The number is not divisibl~ by 11\n");
}

out put ::
Enter the numher to be tested 121
The number is divisible by 11

Enter the numher to be tested 12345
The number is not divisibl~ by 11




No comments:

Post a Comment

python class topic video