Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- struct Item {
- char name[15];
- int prize;
- int id;
- };
- int total_prize(struct Item *, int);
- int main() {
- struct Item item_1 = {"Iphone 7", 899, 1};
- struct Item item_2 = {"Samsung Note8", 1000, 2};
- struct Item item_3 = {"Pixel2", 499, 3};
- struct Item all_items = (item_1, item_2, item_3);
- struct Item array_of_items[3] = {all_items};
- int total = total_prize(array_of_items, 3);
- printf("Total prize of items is: $%d", total);
- return 0;
- }
- int total_prize(struct Item item[], int array_size) {
- int total = 0;
- for (int i = 0; i < array_size; i++) {
- total += item[i].prize;
- }
- return total;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement