Home > Study > C Language > C Example > [ex02] 다양한 입력 및 출력 연습

[ex02] 다양한 입력 및 출력 연습
Study Language

문제 설명


다음 코드에 들어갈 입력 및 인쇄 코드를 설계하라
입력 예시와 같이 입력 시 출력 예시와 같이 인쇄가 되어야 한다
[주의] printf 사용시 출력 예시와 완전히 동일하도록 공백, ‘,’ 등의 인쇄에 주의하여야 한다

#include <stdio.h>

void main(void)
{
	char name[31];
	int age;
	float height;
	char blood_type;
	char nationality[11];

	// 코드 작성

}

입력 예시


Hong Gil Dong
100
182.9
A
KOR

출력 예시


Hong Gil Dong, 100, 182.899994
A, KOR

정답 코드


#include <stdio.h>
 
void main(void)
{
    char name[31];
    int age;
    float height;
    char blood_type;
    char nationality[11];
 
    // 코드 작성
    gets(name);
    scanf("%d %f %c %s", &age, &height, &blood_type, nationality);
    printf("%s, %d, %f\n", name, age, height);
    printf("%c, %s", blood_type, nationality);
 
}

메모


printf 내부의 \n 습관화 필요