고흐의 연구실/자료구조와 알고리즘
[프로그래머스] 짝수와 홀수 (C언어, python)
전고흐
2020. 9. 1. 01:09
728x90
프로그래머스 문제.
짝수와 홀수
C언어와 파이썬으로 풀었습니다.
ㅇ문제
ㅇC언어
1
2
3
4
5
6
7
8
9
10
11
12
|
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
char* solution(int num) {
// 리턴할 값은 메모리를 동적 할당해주세요
char* answer = (char*)malloc(sizeof("Even "));
if(num%2==0){
answer = "Even";
} else answer = "Odd";
return answer;
}
|
cs |
ㅇ파이썬
def solution(num):
return "Even" if num%2==0 else "Odd"
728x90