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