Ex7-pareseimpares.txt

  • Uploaded by: Gustavo Sousa
  • 0
  • 0
  • May 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Ex7-pareseimpares.txt as PDF for free.

More details

  • Words: 107
  • Pages: 1
#include <stdio.h> #include <stdlib.h> int compare_ints(int a, int b) { int cmp_par_impar = a % 2 - b % 2; if (cmp_par_impar != 0) return cmp_par_impar; return a % 2 == 0 ? a - b : b - a; } int compare_int_ptrs(const void *ap, const void *bp) { int a = *((int *) ap); int b = *((int *) bp); }

return compare_ints(a, b);

int main(void) { unsigned int n, i; scanf("%u", &n); int vetor[n]; for (i = 0; i < n; i++) { scanf("%d", &vetor[i]); } qsort(vetor, n, sizeof(int), compare_int_ptrs); for (i = 0; i < n; i++) { printf("%d\n", vetor[i]); } return 0; }

More Documents from "Gustavo Sousa"

Ex4-cedulas.txt
May 2020 7
November 2019 9
Ex3-bhaskara.txt
May 2020 12