、判断用户输入的整数能否被2,3,5整除,并根据情况输出以下信息之一:

1个回答

  • #include "stdio.h"

    main()

    {

    int i,a;

    printf("input the number:");

    scanf("%d",&a);

    if(!((a%2)||(a%3)||(a%5)))

    printf(" %d can be divided with no remainder by 2,3 and 5.",a);

    else if((a%2==0)&&(a%3==0)&&(a%5!=0))

    printf(" %d can be only divided with no remainder by 2 and 3.",a);

    else if((a%2==0)&&(a%3!=0)&&(a%5==0))

    printf(" %d can be only divided with no remainder by 2 and 5.",a);

    else if((a%2!=0)&&(a%3==0)&&(a%5==0))

    printf(" %d can be only divided with no remainder by 3 and 5.",a);

    else if((a%2==0)&&(a%3!=0)&&(a%5!=0))

    printf(" %d can be only divided with no remainder by 2 .",a);

    else if((a%2!=0)&&(a%3==0)&&(a%5!=0))

    printf(" %d can be only divided with no remainder by 3.",a);

    else if((a%2!=0)&&(a%3!=0)&&(a%5==0))

    printf(" %d can be only divided with no remainder by 5.",a);

    else if((a%2)&&(a%3)&&(a%5))

    printf(" %d can't be divided with no remainder by 2,3 and 5.",a);

    }