this algorithm is to verify divisor

Asked

Viewed 31 times

-1

this algorithm is to check if the first is splitter of the second and at the end show whether it is splitter or not splitter, no error, but do not know how to continue

#include <stdio. h> #include <conium. h> int main() { int n1,N2,rest,res;

printf (" Type a number:"); scanf ("%d", &n1);

printf (" Type a number:"); scanf ("%d", &N2);

res = n1 / N2; rest= n1%N2;

printf(" nResulted from %d / %d = %d. n",n1,N2,res);

getch(); Return(0); }

  • Hi Eleny, I believe the way you asked the question doesn’t fit Sopt’s question protocols. Have a look https://answall.com/help/how-to-ask, it might help. and make it easier to answer your question.

  • Appendage if (n1 % n2 == 0)&#xA; printf(%d é divisor de %d\n", n2, n1);&#xA;else&#xA; printf(%d não é divisor de %d\n", n2, n1);&#xA;

  • Attention just what you posted: verificar se o primeiro é divisor do segundo, in this case reversed n1 and n2 because the answer above is whether n2 is or is not a divisor of n1.

1 answer

1

If A divides B, the rest of the division of A by B is zero, i.e. a%b == 0.

Just do:

if(resto == 0)
   printf("\n%d é divisor de %d!",n1,n2);
else
   printf("\n%d não é divisor de %d!",n1,n2)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.