the greatest 1013 URI judge beecrowd bee crowd ab (a+b+abs(a+b))/2 abs() c programming solution python alpha codist coding problem solved .c .py
The Greatest
This problem is from beeCrowd. This is a simple program where you have to use a formula to get the largest number among three numbers.
The formula is:
For two numbers AB it will be-- (a+b+abs(a+b))/2
Note that here "abs()" is a function that gives you the absolute value of any number given in the input. With this, you will get a larger one between A and B. Put the value of this in a variable(ex: ab) and calculate again using the same formula. Just replace "a" with your variable and "b" with your third number. So the solution will be.
The solution in C:
#include <stdio.h>
int main() {
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
int ab = ((a+b)+abs(a-b))/2;
int abc = ((ab+c)+abs(ab-c))/2;
printf("%d eh o maior\n",abc);
return 0;
}
The solution in Python:
import math
a, b, c = input().split(" ")
ab = (int(a) + int(b) + abs(int(a) - int(b))) / 2
ab_c= (int(ab) + int(c) + abs(int(ab) - int(c)))/2
print("%d eh o maior" %ab_c)
COMMENTS