Last active
June 6, 2021 03:30
-
-
Save ozscosta/b89e3601e611222f1055d8a9b24913a3 to your computer and use it in GitHub Desktop.
Divisão apenas com subtração
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() { | |
int dividendo; | |
int divisor; | |
int resultado = 0; | |
int resto = 0; | |
printf("Dividendo: "); | |
scanf("%d", ÷ndo); | |
printf("Divisor: "); | |
scanf("%d", &divisor); | |
while (1) { | |
if (dividendo < divisor) { | |
if (dividendo > 0) { | |
resto = dividendo; | |
} | |
break; | |
} | |
dividendo -= divisor; | |
resultado++; | |
} | |
printf("Resultado: %d\n", resultado); | |
if (resto > 0) { | |
printf("Resto: %d\n", resto); | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dividendo = int(input("Dividendo: ")) | |
divisor = int(input("Divisor: ")) | |
resultado = 0 | |
resto = 0 | |
while True: | |
if dividendo < divisor: | |
if dividendo > 0: | |
resto = dividendo | |
break | |
dividendo -= divisor | |
resultado += 1 | |
print(f"resultado: {resultado}") | |
if resto: | |
print(f"resto: {resto}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment