Advertisement
PitPlayfun

funkcja_sum_cen

Feb 21st, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.69 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. struct Item {
  4.     char name[15];
  5.     int prize;
  6.     int id;
  7. };
  8.  
  9. int total_prize(struct Item *, int);
  10.  
  11. int main() {
  12.  
  13.     struct Item item_1 = {"Iphone 7", 899, 1};
  14.     struct Item item_2 = {"Samsung Note8", 1000, 2};
  15.     struct Item item_3 = {"Pixel2", 499, 3};
  16.     struct Item all_items = (item_1, item_2, item_3);
  17.     struct Item array_of_items[3] = {all_items};
  18.    
  19.     int total = total_prize(array_of_items, 3);
  20.     printf("Total prize of items is: $%d", total);
  21.  
  22.     return 0;
  23. }
  24.  
  25. int total_prize(struct Item item[], int array_size) {
  26.     int total = 0;
  27.     for (int i = 0; i < array_size; i++) {
  28.         total += item[i].prize;
  29.     }
  30.     return total;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement