Write a program to get integer input from the user and print "FOOBAR" if the
number is divisible by 3 & 5 and print "F00" if the number is divisible by 3 and
print "BAR" if the number is divisible by 5 and print "NONE" if the number is not
divisible by 3 and 5.
Sample testcases
Input 1
Output 1
15
F00BAR
Input 2
Output 2
45
F00BAR
Input 3
Output 3
9
FOO
Input 4
Output 4
11
NONE
Answers
Answer:
num=int(input('ENTER YOUR NO.='))
if num%3==0 and num%5==0:
print('F00BAR')
elif num%3==0:
print('F00')
elif num%5==0:
print('BAR')
else:
print('NONE')
1.
ENTER YOUR NO.=15
F00BAR
2.
ENTER YOUR NO.=45
F00BAR
3.
ENTER YOUR NO.=9
F00
4.
ENTER YOUR NO.=4
NONE
✨
Answer:
#include<stdio.h>
int main()
{
int i, num;
//Asking for input
printf("Enter the number: ");
scanf("%d", &num);
if (num % 3 == 0 && num % 5 == 0)
{
printf(" FOOBAR %d ", num);
}
else {
if(num % 3 == 0)
printf(" FOO %d ", num);
else{
if (num % 5 == 0)
printf(" Bar %d ", num);
else
printf(" None %d ", num);
}
}
return 0;
}
Explanation:
Input : 15
Output : FOOBAR 15
Input : 45
Output : FOOBAR 45
Input : 9
Output : FOO 9
Input : 11
Output : None 15