marcelofoxes

returning two values using pointers

Oct 31st, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.56 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. void getMaiorEMenor(int vetor[], int *menor, int *maior) {
  5.     int aux;
  6.     int index;
  7.     for (index = 0; index < sizeof(vetor); index++) {
  8.         int current = vetor[index];
  9.         if (current > *maior) {
  10.           *maior = current;
  11.         }
  12.  
  13.         if (current < *menor) {
  14.           *menor = current;
  15.         }
  16.     }
  17. }
  18.  
  19.  
  20. int main(int argc, char const *argv[]) {
  21.     int numeros[4] = {2, 5, 1, 4};
  22.     int maior, menor;
  23.     getMaiorEMenor(numeros, &menor, &maior);
  24.     printf("%d %d\n", menor, maior);
  25. }
Advertisement
Add Comment
Please, Sign In to add comment