Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- typedef struct
- {
- char product_name[25];
- double price;
- } Product;
- void ordenation(double array[], int i, int j, int aux, int tamanho) {
- if (i != tamanho - 1)
- {
- if (j < tamanho)
- {
- if (array[i] > array[j])
- {
- aux = array[i];
- array[i] = array[j];
- array[j] = aux;
- }
- ordenation(array, i, ++j, aux, tamanho);
- }
- ordenation(array, ++i, j, aux, tamanho);
- }
- }
- int main()
- {
- double money, products_sum = 0; /* products_sum vai ser a soma dos preços dos produtos para verificar até qual o usuário pode comprar */
- int number_of_items, i;
- scanf("%lf\n", &money);
- scanf("%d\n", &number_of_items);
- Product products[number_of_items];
- for (i = 0; i < number_of_items; i++)
- {
- scanf("%s %lf", products[i].product_name, &products[i].price);
- }
- ordenation(products.price, 0, 0, 0, number_of_items);
- for (i = 0; i < number_of_items; i++)
- {
- printf("%s %.2lf\n", products[i].product_name, products[i].price);
- }
- for (i = 0; i < number_of_items; i++)
- {
- if ((money - products_sum) > 0)
- {
- products_sum += products[i].price;
- }
- else
- {
- /* TODO: imprimir todos os itens que, somados, não ultrapassem o valor em dinheiro */
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement