Checking the Entered Number Is Divisible By 11 Or Not
Source code :-
#include<stdio.h>
int main()
{
int n,i=0,r,x=0,y=0;
printf("Enter the number: ");
scanf("%d",&n);
while(n!=0)
{
i++;
r=n%10;
if(i%2==0)
x=x+r;
else
y=y+r;
n=n/10;
}
if(x==y)
printf("\nThe number is divisible by 11\n");
else
printf("\nThe number is not divisible by 11\n");
return 1;
}
int main()
{
int n,i=0,r,x=0,y=0;
printf("Enter the number: ");
scanf("%d",&n);
while(n!=0)
{
i++;
r=n%10;
if(i%2==0)
x=x+r;
else
y=y+r;
n=n/10;
}
if(x==y)
printf("\nThe number is divisible by 11\n");
else
printf("\nThe number is not divisible by 11\n");
return 1;
}
Input-Output :-
abhi@hp-15q-laptop:~$ gcc divby11.c
abhi@hp-15q-laptop:~$ ./a.out
Enter the number: 121
The number is divisible by 11
abhi@hp-15q-laptop:~$ ./a.out
Enter the number: 121
The number is divisible by 11
abhi@hp-15q-laptop:~$ gcc divby11.c
abhi@hp-15q-laptop:~$ ./a.out
Enter the number: 123
The number is not divisible by 11
abhi@hp-15q-laptop:~$ ./a.out
Enter the number: 123
The number is not divisible by 11
Post a Comment