Hello, I want to enter 4 numbers and display the largest possible number. Can anybody help me with this please? I have tried multiply different approaches, so do not wonder why there are so many libraries. Thanks in advance
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h> //pow
#include <limits.h> //char max
#include <ctype.h> //
int sort_alg(const void *a, const void *b)
{
char ab[32], ba[32];
sprintf(ab, "%d%d", *(int*)a, *(int*)b);
sprintf(ba, "%d%d", *(int*)b, *(int*)a);
return strcmp(ba, ab);
}
void max_numb(int *a, int len)
{
int i;
qsort(a, len, sizeof(int), sort_alg);
for (i = 0; i < len; i++)
printf("%d", a[i]);
putchar('\n');
}
int main(void)
{
int numbers[4];
for(int count = 0; count < 4; count++)
{
scanf("%d", &numbers[count]);
printf("%d", numbers);
}
max_numb(numbers, sizeof(numbers)/sizeof(numbers[0]));