Jump to content
Fórum Script Brasil
  • 0

linguagem c


burns

Question

1 answer to this question

Recommended Posts

  • 0

#include <stdio.h>
#include <stdlib.h>

int lerNumero();
void ordenar(int* numeros, int n);

int main(int argc, char *argv[]) {
  int numeros[10];
  int i;

  for(i = 0; i < 10; ++i) {
    numeros[i] = lerNumero();
  }

  ordenar(numeros, sizeof(numeros) / sizeof(int));

  printf("Os tres maiores numeros são: %d, %d, %d\n", numeros[9], numeros[8], numeros[7]);
  getchar();

  return 0;
}

int lerNumero() {
  char string[1024];
  int numero;

  fgets(string, 1024, stdin);
  numero = atoi(string);

  return numero;
}

int comparar(const void* a, const void* b) {
  return (*(int*) a - *(int*) b);
}

void ordenar(int* numeros, int n) {
  qsort(numeros, n, sizeof(int), comparar);
}

Tá na mão.

Abraços.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...