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
'고흐의 연구실 > 자료구조와 알고리즘' 카테고리의 다른 글
[프로그래머스] 3진법 뒤집기(C++) (0) | 2020.10.23 |
---|---|
[자료구조] 정리하기(작성중) (0) | 2020.10.21 |
[자료구조/C언어] 연결리스트 / 링크드 리스트 / linked list (0) | 2020.09.30 |
[알고리즘] 거품 정렬 (bubble sort) (0) | 2020.09.01 |
백준 1476번 : 날짜 계산 (0) | 2018.01.12 |