본문 바로가기
프로그래머스코딩테스트연습풀이/C언어

[프로그래머스/C언어] 간단한 논리 연산

by 코코쵸마 2023. 7. 31.

문제

boolean 변수 x1, x2, x3, x4가 매개변수로 주어질 때, 다음의 식의 true/false를 return 하는 solution 함수를 작성해 주세요.

(x1 ∨ x2) ∧ (x3 ∨ x4)

 

솔루션

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

bool solution(bool x1, bool x2, bool x3, bool x4) {
    bool answer = true;
    bool answer1 = true;
    bool answer2 = true;
    
    answer1 = (!x1 && !x2)? false : true;
    answer2 = (!x3 && !x4)? false : true;
    answer = (answer1 && answer2)? true : false;
    return answer;
}

https://school.programmers.co.kr/learn/courses/30/lessons/181917

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr