Algorithm
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/1013
The Greatest
Adapted by Neilor Tonin, URI Brazil
Make a program that reads 3 integer values and present the greatest one followed by the message "eh o maior". Use the following formula:
Input
The input file contains 3 integer values.
Output
Print the greatest of these three values followed by a space and the message “eh o maior”.
Input Samples | Output Samples |
7 14 106 |
106 eh o maior |
217 14 6 |
217 eh o maior |
Code Examples
#1 Code Example with C Programming
Code -
C Programming
#include<stdio.h>
int main()
{
int a,b,c,major,MaiorAB;
scanf("%d %d %d" ,&a ,&b ,&c);
MaiorAB = (a+b+abs(a-b))/2;
major = (MaiorAB+c+abs(MaiorAB-c))/2;
printf("%d eh o maior",major);
printf("\n");
return 0;
}
Copy The Code &
Try With Live Editor
Input
Output
#2 Code Example with C++ Programming
Code -
C++ Programming
#include <iostream>
using namespace std;
int main() {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
if (a >= b && a >= c)
printf("%d eh o maior\n", a);
else if (b >= a && b >= c)
printf("%d eh o maior\n", b);
else
printf("%d eh o maior\n", c);
return 0;
}
Copy The Code &
Try With Live Editor
Input
Output
#3 Code Example with Javascript Programming
Code -
Javascript Programming
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
let linhas = input.split('\n');
let entrada = linhas.shift().split(' ');
let a = parseInt(entrada[0]);
let b = parseInt(entrada[1]);
let c = parseInt(entrada[2]);
let result = parseInt((a + b + Math.abs(a - b)) / 2);
let maior = parseInt((result + c + Math.abs(result - c)) / 2);
console.log(maior, "eh o maior");
Copy The Code &
Try With Live Editor
Input
Output
#4 Code Example with Python Programming
Code -
Python Programming
a, b, c = input().split(" ")
maior = (int(a) + int(b) + abs(int(a) - int(b))) / 2
resultado = (int(maior) + int(c) + abs(int(maior) - int(c))) / 2
print(f'{int(resultado)} eh o maior')
Copy The Code &
Try With Live Editor
Input
Output