728x90
반응형
문제 : https://codeup.kr/problem.php?id=1205
문제 설명
두 실수 a, b가 입력되면 그 두수를 더하거나 빼거나 곱하거나 나누거나 제곱을 해서 가장 큰 수를 출력하시오.
예를 들어 1과 2가 입력되면,
1+2 = 3 , 2+1 = 3
1 - 2 = -1, 2 - 1 = 1
1 * 2 = 2, 2 * 1 = 2
1 / 2 = 0.5, 2 / 1 = 2
12=1 , 21 = 2
따라서 최댓값은 3이다.
#include <stdio.h>
#include <math.h>
int main()
{
float a, b;
float plus, minus, minus2, multi, div, div2, math, math2, result;
scanf("%f %f", &a, &b);
plus=a+b; // +연산
minus=a-b; // -연산 1
minus2=b-a; // -연산 2
multi=a*b; // X연산
div=a/b; // /연산 1
div2=b/a; // /연산 2
math=pow(a,b); // 제곱연산 1
math2=pow(b,a); // 제곱연산 2
result=plus>=minus ? plus:minus;
result=result>=minus2 ? result:minus2;
result=result>=multi ? result:multi;
result=result>=div ? result:div;
result=result>div2 ? result:div2;
result=result>math ? result:math;
result=result>math2 ? result:math2;
printf("%lf", result);
return 0;
}
728x90
반응형
최근댓글