Input Positive Number and Find If it is Divisible by 5 or(||) 3 But Not 15.
In this program we will be able to see that any number which is divisible by either 3 or (||) 5 but not by 15. We can check that number. Or the number which is divisible only by 15.
Code:
// number is divisible by 5 or(||) 3 but not 15.
// Using c program
#include <stdio.h>
int main()
{
int num;
printf("Enter any number:");
scanf("%d", &num);
if (num % 5 == 0 || num % 3 == 0)
{
if (num % 15 != 0)
{
printf("The number - %d is divisible by 5 or 3 but not 15. ",num);
}
else
{
printf("The number - %d is divisible by 15. ",num);
}
}
else
{
printf("The number - %d is not divisible 5 or 3. ",num);
}
return 0;
}
Explanation:
Using this program we can get the number which is divisible by 3 or 5 but not by 15. For this we have used or (||) operator like 3, 5, 6, 9, 12, 15,.....
Output:
Enter any number: 5
The number - 5 is divisible by 5 or 3 but not 15.
Enter any number: 9
The number - 9 is divisible by 5 or 3 but not 15.
Enter any number: 15
The number - 15 is divisible by 15:
