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"); } }
4 Respuestas
+ 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)
+ 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);
+ 1
Okk
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.