What's new

Help Compare 4 integers and find the difference

Phantom Rhythm

Honorary Poster
Joined
Sep 10, 2018
Posts
682
Reaction
69
Points
207
pa help po ito po
code:
#include <stdio.h>
int main() {
int a1, a2, a3, a4;
int max, min;

scanf("%d %d %d %d", & a1, & a2, & a3, & a4);
if (a1 >= a2 && a1 >= a3 && a1 >= a4)
max = a1;
else if (a2 >= a1 && a2 >= a3 && a2 >= a4)
max = a2;
else if (a3 >= a1 && a3 >= a2 && a3 >= a4)
max = a3;
else
max = a4;
if (a1 <= a2 && a1 <= a3 && a1 <= a4)
min = a1;
else if (a2 <= a1 && a2 <= a3 && a2 <= a4)
min = a2;
else if (a3 <= a1 && a3 <= a2 && a3 <= a4)
min = a3;
else
min = a4;
printf("%d", max - min);
return 0;
}

Input

1 2 3 4
Your Output

3
Expected Output

-2
 
Kung difference ng lahat ng input ang hinahanap ts minus mo lang.
C:
int difference = a4 - a3 - a2 - a1;
Output:
1634952594809.png
 

Attachments

may repetitive statements naba tinuro sa inyo o conditional statements palang TS?
and also kindly clarify ano and expected output mo po at kindly give table of input and expected output para malinaw
 
Last edited:
may repetitive statements naba tinuro sa inyo o conditional statements palang TS?
and also kindly clarify ano and expected output mo po at kindly give table of input and expected output para malinaw
meron na pong repetitive statement
input
1 2 3 4

Output

-2

input
1 -1 1 -1

Output
4

Input
-1000 -1000 -1000 -1000

Output
0
 

Similar threads

Back
Top