• API
• FAQ
• Tools
• Archive
daily pastebin goal
70%
SHARE
TWEET

# Untitled

a guest Mar 24th, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include <stdio.h>
2.
3. #define N 10
4. #define M 11
5. #define X 6
6.
7. void swap(int *max, int *min)
8. {
9.     if (*min > *max)
10.     {
11.         int temp = *max;
12.         *max = *min;
13.         *min = temp;
14.     }
15. }
16.
17. void minmax(int *arr, int n, int *max, int *min)
18. {
19.     int Lmax, Rmax, Lmin, Rmin;
20.
21.     if (n == 0)
22.     {
23.         *min = *max = -1;
24.         return;
25.     }
26.
27.     if (n == 1)
28.     {
29.         *min = *max = arr[0];
30.         return;
31.     }
32.
33.     if (n == 2)
34.     {
35.         *max = arr[0];
36.         *min = arr[1];
37.         swap(max,min);
38.         return;
39.     }
40.
41.     minmax(arr,n/2,&Lmax,&Lmin);
42.     minmax(arr+(n/2),(n/2)+(n%2),&Rmax,&Rmin);
43.
44.     *max = (Lmax > Rmax)? Lmax : Rmax;
45.     *min = (Lmin < Rmin)? Lmin : Rmin;
46. }
47.
48. int abs(int value)
49. {
50.     if (value < 0)
51.         return value*(-1);
52.     return value;
53. }
54.
55. void findDouble(int *arr, int n)
56. {
57.     int i;
58.     for (i=0;i<n+2;i++)
59.     {
60.         if (arr[abs(arr[i]) - 1] < 0)
61.         {
62.             printf("Value is: %d\n",arr[i]);
63.         }
64.         else
65.         {
66.             arr[abs(arr[i]) - 1] = arr[abs(arr[i]) - 1] * (-1);
67.         }
68.     }
69. }
70.
71. void main()
72. {
73.     int max,min;
74.     int arr1[N] = {3,1,17,9,4,2,27,21,7,10};
75.     int arr2[M] = {6,5,4,8,1,90,11,21,34,32,33};
76.     int arr3[X+2] = {1,3,2,2,5,5,6,4};
77.
78.     findDouble(arr3,X);
79.
80.     minmax(arr1,N,&max,&min);
81.     printf("max = %d, min = %d\n",max,min);
82.
83.     minmax(arr2,M,&max,&min);
84.     printf("max = %d, min = %d\n",max,min);
85. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top