Advertisement
dusanrs

min_maks

Apr 18th, 2022
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.02 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int* CalculateMinMax(char* buffer,int n);
  5.  
  6.  
  7.  
  8. int main()
  9. {
  10.     int n;
  11.     int *resenje;
  12.     char niz[n];
  13.     printf("Unesite koliko zelite brojeva");
  14.     scanf("%d",&n);
  15.     for(int i=0;i<n;i++){
  16.         printf("Unesite broj");
  17.         scanf("%hu",niz+i*sizeof(short));
  18.     }
  19.  
  20.  
  21.     resenje=CalculateMinMax(niz,n);
  22.  
  23.     printf("\nMinimum %hu",*((short*)(resenje+sizeof(short))));
  24.     printf("\nMakasimum %hu",*((short*)resenje));
  25.  
  26.     return 0;
  27. }
  28.  
  29.  
  30.  int * CalculateMinMax(char* buffer,int n){
  31.  
  32.  
  33.     int *resenje=(int*)malloc(sizeof(int));
  34.  
  35.  
  36.     *((short*)resenje)= *((short*)buffer);
  37.     *((short*)(resenje+sizeof(short)))= *((short*)buffer);
  38.  
  39.     for(int i=0;i<n;i++){
  40.         if(*((short*)buffer+i)<*((short*)(resenje+sizeof(short)))){
  41.             *((short*)(resenje+sizeof(short)))=*((short*)buffer+i);
  42.         }else if(*((short*)buffer+i)>*((short*)resenje)){
  43.             *((short*)resenje)=*((short*)buffer+i);
  44.         }
  45.     }
  46.  
  47.     return resenje;
  48.  
  49.  
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement