🔒 Closed Compare 4 integers and find the difference

Status
Not open for further replies.

Phantom Rhythm

Honorary Poster
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
 
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
 
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
 
Status
Not open for further replies.

About this Thread

  • 10
    Replies
  • 452
    Views
  • 3
    Participants
Last reply from:
Phantom Rhythm

Trending Topics

Online now

Members online
733
Guests online
1,624
Total visitors
2,357

Forum statistics

Threads
2,289,989
Posts
29,061,847
Members
1,213,094
Latest member
lester0224
Back
Top