I can not make this program work. Always says numbers are divisible

1
#include <stdio.h>
#include "funcao.h"

int main () {
    int a, b;
    printf("Escreva os valores de a e b   ");
    scanf("%d", &a);
    scanf("%d", &b);

    if (EDivisivel (a,b))
        printf("sao divisiveis");
    else
        printf("nao sao divisiveis");
        return (0);
}

/ * function is down here: * /

#include <stdio.h>
int EDivisivel (int a, int b) {
    if (a%b)
        return 1;
    else
        return 0;
}

From this, I never get certain results from non-divisible numbers

    
asked by anonymous 27.11.2016 / 16:35

1 answer

1

For one number to be considered divisible by another the remainder of the division (%) between them must be equal to 0. Ex: 6/3 = 2 and remainder = 0.

When you do if (a%b) , this condition will be true if the rest of the division equals 1. For 1 - > True and 0 - > False.

So, the correct thing would be to check: if (a%b == 0) .

    
27.11.2016 / 16:49