Guest User

Untitled

a guest
Jun 18th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.61 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct{
  5.     int max;
  6.     int max2;
  7.  }max2_t;
  8.  
  9. max2_t max2(const int *begin, const int *end){
  10.     max2_t m;
  11.     int max=*begin;
  12.     int max2=*begin;
  13.     if(max==max2){
  14.         max2=*(begin+1);
  15.     }
  16.     while(begin!=end){
  17.         if(*begin>max){
  18.             max2=max;
  19.             max=*begin;
  20.         }else if(*begin>max2 && *begin!=max){
  21.             max2=*begin;
  22.         }
  23.         begin++;
  24.     }
  25.     m.max=max;
  26.     m.max2=max2;
  27.     return m;
  28. }
  29.  
  30. int main(int argc, char ** argv){
  31.     int begin[14]={14,1,2,3,4,5,6,7,8,9,13,10,11,36};
  32.     int* end=begin+14;
  33.     max2_t m = max2(begin,end);
  34.     printf("Max=%d\n2.Max=%d\n",m.max,m.max2);
  35.     return 0;
  36. }
Add Comment
Please, Sign In to add comment