Write a program that checks whether an integer number is divisible by 2 and 3, by 2 or 3, and by 2 or 3 but not both.

+1 vote
asked Mar 23, 2019 by anonymous
Write a program that checks whether an integer number is divisible by 2 and 3, by 2 or 3, and by 2 or 3 but not both.

4 Answers

0 votes
answered Mar 25, 2019 by Nitin Rauthan
#include <stdio.h>

int check_div(int n)
{
    
    if(n%2==0)
    {
        if(n%3==0)
        {
        printf("Divisible by 2 and 3 both\n");
        return 1;
        }
        printf("Divisible by 2 only\n");
        return 2;
    }
    if(n%3==0)
    {   
        printf("Divisible by 3 only\n");
        return 3;
    }
    
    printf("Neither Divisible by 2 nor 3\n");
    return 0;
    
}

int main()
{
   int n;
   
   printf("Enter the number\n");
   
   scanf("%d",&n);
   
   check_div(n);

    return 0;
}
0 votes
answered Jul 30, 2019 by anonymous
#include<stdio.h>

int main(){

int a;

scanf("%d",&a);

if(a%6==0)

printf("divisible by both 2 and 3");

else if(a%2==0)

printf("divisible by 2");

else if (a%3==0)

printf("divisible by 3");

else

printf("divisible by neither 2 nor 3");

return 0;

}
0 votes
answered Jul 31, 2019 by keerthanav666 (300 points)
#include<stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    if(n%6==0)
    {
        if(n%3==0&&n%2==0)
        printf("divisible by both 3 and 2");
        else if(n%3==0)
        printf("divisible by 3");
        else if(n%2==0)
        printf("divisible by 2");
    else if(n%2!=0&&n%3!=0)
     printf("neither 2 nor 3");
    }
    else
    printf("no");
    return 0;
}
0 votes
answered Aug 1, 2019 by Loki (1,600 points)

#include <stdio.h>
void main()
{
    int a;
    printf("%s",(a%2==0)?(a%3==0)?"2and3":"2not3":(a%3==0)?"3not2":"none",scanf("%d",&a));
}

Try this one . wink

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...