Advertisement
amitsp21

Untitled

Dec 19th, 2018
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.32 KB | None | 0 0
  1. int max_value(list<int> a) {
  2.   int max_val;
  3.   int i;
  4.   max_val = -1; // assume all elements are positive
  5.   for (i = 0; i < #a; ++i) {
  6.     if (a[i] > max_val) {
  7.       max_val = a[i];
  8.     }
  9.   }
  10. }
  11.  
  12. int main() {
  13.   list<int> a;
  14.   a = [4, 10, 40, 23, 85, 2];
  15.   printi(max_value(a));
  16.   return 0;
  17. }
  18.  
  19. output: 85
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement