Tuesday, March 5, 2024

44. Input a number and check it is divisible by 3 or divisible by 5 or divisible by both or divisible by none :—

 44. Input a number and check it is divisible by 3 or divisible by 5 or divisible by both or divisible by none :—


#include<stdio.h>

int main()

{

    int a;

    printf("enter a value of n ");

    scanf("%d",&a);

    if(a%3==0)

    {

        if(a%5==0)

        {

            printf("%d is divisible by both",a);

        }

        else

        {

            printf("%d is divisible by 3 only",a);

        }

    }

    else

    {

        if(a%5==0)

        {

            printf("%d is divisible by 5 only",a);

        }

        else

        {

            printf("%d is divisible by none of 5 and 3",a);

        }

    }

    return 0;

}


No comments:

Post a Comment