0

Write a program to input integer no. from the keyboard and check if it is divisible by 3 and 5. Plz check my program in c langua

#include<stdio.h> void main() { int num; printf ("Enter anl integer: "); scanf("%d", num); if( (num 3 == 0 ) && (num 5 == 0)) ; { printf ("Number is divisible by 3 and 5"); } else { printf ("Number is not divisible by 3 and 5"); } }

30th Mar 2020, 5:37 AM
Khushi Gupta
4 Antworten
+ 2
There should be || not && if you want number divisible by 3 or 5 Khushi Gupta condition would be like this if(num % 3 == 0 || num % 5 == 0) Edited - If you want that number only which is divisible by both 3 and 5 then there would be && In this case condition would be if(num % 3 == 0 && num % 5 == 0)
30th Mar 2020, 5:39 AM
A͢J
A͢J - avatar
+ 2
return type of main function must be `int`. scanf is called wrong way. its should be : scanf("%d",&num); Remove semicolon after if(condition);
30th Mar 2020, 5:42 AM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
+ 1
Okk
30th Mar 2020, 5:39 AM
Khushi Gupta
0
I did some corrections in your code, check this #include<stdio.h> int main() { int num; printf ("Enter anl integer: "); scanf("%d", &num); if( (num %3 == 0 ) && (num %5 == 0)) ; { printf ("Number is divisible by 3 and 5"); } else { printf ("Number is not divisible by 3 and 5"); } } corrections: use '&' in scanf to specify address and '%' operator for remainder.
30th Mar 2020, 10:05 AM
Sunil
Sunil - avatar