Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * File: Coin Row Problem
- * Author: Fernando Alva Manchego
- *
- */
- #include <stdio.h>
- #include <stdlib.h>
- /*
- *
- */
- #define MAX_MONEDAS 6
- int max(int val1, int val2){
- if (val1>val2)
- return val1;
- else
- return val2;
- }
- int coin_row(int cantidades[], int monedas[]){
- int i;
- cantidades[0] = 0;
- cantidades[1] = monedas[0];
- for (i=2; i<=MAX_MONEDAS; i++){
- cantidades[i] = max(monedas[i-1] + cantidades[i-2], cantidades[i-1]);
- }
- return cantidades[MAX_MONEDAS];
- }
- void pprint(int cantidades[]){
- int i;
- for (i=0; i<=MAX_MONEDAS;i++)
- printf("%d ", cantidades[i]);
- }
- int main(int argc, char** argv) {
- int monedas[MAX_MONEDAS] = {5,1,2,10,6,2};
- int cantidades[MAX_MONEDAS+1];
- printf("%d\n", coin_row(cantidades,monedas));
- printf("Estructura Auxiliar:\n");
- pprint(cantidades);
- return (EXIT_SUCCESS);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement