#define _crt_secure_no_warnings
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
void sortAbs(int* a, int* b, int* c);
int main()
{
int *a, *b, *c;
int max, mid, min;
printf ("Enter 3 integers:");
scanf("%d,%d,%d", &a,&b,&c);
sortAbs(&a, &b, &c);
printf("%d,%d,%d", min, mid, max);
}
void sortAbs(int *a, int *b, int *c)
{
int tmp;
int max, mid, min;
if (abs(*a) >= abs(*b) && abs(*a) >= abs(*c))
{
max = *a;
if (abs(*b) >= abs(*c))
{
mid = *b;
min = *c;
}
else if(abs(*c) >= abs(*b))
{
mid = *c;
min = *b;
}
}
if (abs(*b) >= abs(*a) && abs(*b) >= abs(*c))
{
max = *b;
if (abs(*a) >= abs(*c))
{
mid = *a;
min = *c;
}
else if(abs(*c)>= abs(*a))
{
mid = *c;
min = *a;
}
}
if (abs(*c) >= abs(*a) && abs(*c) >= abs(*b))
{
max = *c;
if (abs(*b) >= abs(*a))
{
mid = *b;
min = *a;
}
else if(abs(*c)>= abs(*b))
{
mid = *c;
min = *b;
}
}
return 0;
}
-252 Enter -> -225
-3 -64 When entering -> -34 -6
I made it like this, but there's an error when I type it in What's wrong?
c sorting
Please understand that I can't explain each and every place because there are many mistakes.
Below are the modified codes and results. Check the differences carefully.
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
void sortAbs(int* a, int* b, int* c);
int main()
{
int a, b, c;
//int max, mid, min;
printf ("Enter 3 integers:");
scanf("%d %d %d", &a, &b, &c);
sortAbs(&a, &b, &c);
printf("%d,%d,%d", a, b, c);
}
void sortAbs(int* a, int* b, int* c)
{
//int tmp;
int max, mid, min;
if (abs(*a) >= abs(*b) && abs(*a) >= abs(*c))
{
max = *a;
if (abs(*b) >= abs(*c))
{
mid = *b;
min = *c;
}
else if (abs(*c) >= abs(*b))
{
mid = *c;
min = *b;
}
}
else if (abs(*b) >= abs(*a) && abs(*b) >= abs(*c))
{
max = *b;
if (abs(*a) >= abs(*c))
{
mid = *a;
min = *c;
}
else if (abs(*c) >= abs(*a))
{
mid = *c;
min = *a;
}
}
else if (abs(*c) >= abs(*a) && abs(*c) >= abs(*b))
{
max = *c;
if (abs(*b) >= abs(*a))
{
mid = *b;
min = *a;
}
else if (abs(*c) >= abs(*b))
{
mid = *c;
min = *b;
}
}
*a = min;
*b = mid;
*c = max;
//return 0;
}
© 2024 OneMinuteCode. All rights reserved.