Write a program to check whether entered number is divisible by 8 or not.
#include<stdio.h> int Check_for_Divisible_by_8(int); enum Num_Status{IS_DIVISIBLE_BY_8,IS_NOT_DIVISIBLE_BY_8}; int main() { int num,status; printf("Enter a Number = "); scanf("%d",&num); status = Check_for_Divisible_by_8(num); if(status == IS_DIVISIBLE_BY_8) printf("%d is divisible by 8\n",num); else printf("%d is not divisible by 8\n",num); return 0; } int Check_for_Divisible_by_8(int n) { if((n & 7) == 0) return IS_DIVISIBLE_BY_8; else return IS_NOT_DIVISIBLE_BY_8; }
Output
Enter a Number = 24 24 is divisible by 8
Enter a Number = 45 45 is not divisible by 8