Program to find whether a number is divisible by ‘11’ or not without actual division - 100 Most Important C# Programs

100 Most Important C# Programs

74. Program to find whether a number is divisible by ‘11’ or not without actual division.

Code:

#include<stdio.h>

#include<conio.h>

#include<math.h>

main( )

{

int a,b,n,evensum=0,oddsum=0,div;

clrscr( );

printf(“enter a number”);

scanf(“%d”,&n);

a=n;

b=n/10;

while(a>0)

{

oddsum=oddsum+(a%10);

a=a/10;

}

while(b>0)

{

evensum=evensum+(b%10);

b=b/10;

}

div=abs(evensum-oddsum);

if(div%11==0)

printf(“The number is divisible by 11”);

else

printf(“The number is not divisible by

11”);

getch();

}