Adicionada outras linguagens com o mesmo código para ver qual eu mais gosto

This commit is contained in:
Caio1w
2025-11-02 21:09:12 -03:00
parent 1940701c78
commit abba909b95
8 changed files with 100 additions and 3 deletions

BIN
exercicios-c/a.out Executable file

Binary file not shown.

24
exercicios-c/main.c Normal file
View File

@@ -0,0 +1,24 @@
#include <stdio.h>
int main() {
const int troco = 387;
const int moedas[] = {100, 50, 25, 10, 5, 1};
int valor = 0;
int moedasfinal = 0;
for (int i = 0; i < 6; i++) {
while (valor < troco) {
valor += moedas[i];
moedasfinal += 1;
if (valor > troco) {
valor -= moedas[i];
moedasfinal -= 1;
break;
} else if (valor == troco) {
printf("%d\n", moedasfinal);
break;
}
}
}
return 0;
}

BIN
exercicios-cpp/a.out Executable file

Binary file not shown.

26
exercicios-cpp/main.cpp Normal file
View File

@@ -0,0 +1,26 @@
#include <iostream>
#include <string>
using namespace std;
int main() {
const int troco = 387;
int moedas[] = {100, 50, 25, 10, 5, 1};
int valor = 0;
int moedasfinal = 0;
for (int i = 0; i < 6; i++) {
while (valor < troco) {
valor += moedas[i];
moedasfinal += 1;
if (valor > troco) {
valor -= moedas[i];
moedasfinal -= 1;
break;
} else if (valor == troco) {
cout << moedasfinal << endl;
break;
}
}
}
return 0;
}

25
exercicios-go/main.go Normal file
View File

@@ -0,0 +1,25 @@
package main
import "fmt"
func main() {
const Troco = 187
moedas := []int{100,50,25,10,5,1}
valor := 0
moedasfinal := 0
for _, v := range moedas {
for valor < Troco {
valor += v
moedasfinal++
if valor > Troco {
valor -= v
moedasfinal--
break
} else if valor == Troco {
fmt.Println(moedasfinal)
break
}
}
}
}

BIN
exercicios-java/Main.class Normal file

Binary file not shown.

25
exercicios-java/Main.java Normal file
View File

@@ -0,0 +1,25 @@
public class Main {
public static void main(String[] args) {
final int Troco = 357;
int Valor = 0;
final int[] Moedas = { 100, 50, 25, 10, 5, 1 };
int moedasFinal = 0;
for (int i = 0; i < Moedas.length; i++) {
while (Valor < Troco) {
Valor += Moedas[i];
moedasFinal += 1;
if (Valor > Troco) {
moedasFinal -= 1;
Valor -= Moedas[i];
break;
} else if (Valor == Troco) {
System.out.println(moedasFinal);
return;
}
}
}
}
}

View File

@@ -17,6 +17,3 @@ for moeda in moedasr:
if valor == troco:
print(moedas_final)
break