Adicionada outras linguagens com o mesmo código para ver qual eu mais gosto
This commit is contained in:
		
							
								
								
									
										
											BIN
										
									
								
								exercicios-cpp/a.out
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								exercicios-cpp/a.out
									
									
									
									
									
										Executable file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										26
									
								
								exercicios-cpp/main.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								exercicios-cpp/main.cpp
									
									
									
									
									
										Normal 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;
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user