Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct{
- int max;
- int max2;
- }max2_t;
- max2_t max2(const int *begin, const int *end){
- max2_t m;
- int max=*begin;
- int max2=*begin;
- if(max==max2){
- max2=*(begin+1);
- }
- while(begin!=end){
- if(*begin>max){
- max2=max;
- max=*begin;
- }else if(*begin>max2 && *begin!=max){
- max2=*begin;
- }
- begin++;
- }
- m.max=max;
- m.max2=max2;
- return m;
- }
- int main(int argc, char ** argv){
- int begin[14]={14,1,2,3,4,5,6,7,8,9,13,10,11,36};
- int* end=begin+14;
- max2_t m = max2(begin,end);
- printf("Max=%d\n2.Max=%d\n",m.max,m.max2);
- return 0;
- }
Add Comment
Please, Sign In to add comment