본문 바로가기
프로그래머스 C++/Level.0

프로그래머스 C++ Level. 0 숫자 비교하기

by yeni_0224 2023. 2. 27.
728x90
반응형

정수 num1과 num2가 매개변수로 주어집니다. 두 수가 같으면 1 다르면 -1을 retrun하도록 solution 함수를 완성해주세요.

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>

int solution(int num1, int num2) {
    int answer = 0;
    if(num1 == num2){
        answer = 1;
    }
    else answer = -1;
    
    return answer;
}

if문 사용해서 경우1, -1이 각각 출력될 수 있도록 해주었다

728x90
반응형