Skip to content

Instantly share code, notes, and snippets.

@karol-may
Created October 23, 2011 09:57
Show Gist options
  • Save karol-may/1307197 to your computer and use it in GitHub Desktop.
Save karol-may/1307197 to your computer and use it in GitHub Desktop.
zadanie 23/10/11 8
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* qsort int comparison function */
int int_cmp(const void *a, const void *b)
{
const int *ia = (const int *) a; // casting pointer types
const int *ib = (const int *) b;
return *ia - *ib;
/* integer comparison: returns negative if b > a
and positive if a > b */
}
int main()
{
int sorted[3];
printf("Wprowadź trzy liczby całkowite: ");
scanf("%d %d %d", &sorted[0], &sorted[1], &sorted[2]);
printf("Suma wynosi: %d\n", sorted[0] + sorted[1] + sorted[2]);
printf("Iloczyn wynosi: %d\n", sorted[0] * sorted[1] * sorted[2]);
size_t elemsize = sizeof sorted;
size_t count = sizeof(sorted) / elemsize;
qsort(sorted, count, elemsize, int_cmp);
printf("Najmniejsza liczba to: %d\n", sorted[0]);
printf("Największa liczba to: %d\n", sorted[2]);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment