SlideShare uma empresa Scribd logo
1 de 7
Baixar para ler offline
Standard I/O
Use of printf() and scanf()
 printf()는 Print Format의 약어로, 화면에 내용을 출력할 때 사
용하는 명령(함수)이다.
printf(“format string..”, argument list);

[Ex]
#include <stdio.h>
int main() {
int n ;
n = 25 * 10;
printf(“%d”, n);
}
[Ex]
printf(“%c%c%c”, ’a’, ’b’, ’c’ );
printf(“%s”, “def” );

/* 250 이 출력된다. */

/* abc 가 출력된다. */
/* def 가 출력된다. */

2
Use of printf() and scanf()
 Conversion characters (format string)
%c

character (문자)

printf(“%c”, ’a’);

%d

decimal integer (10진수로출력) printf(“%d”, 100);

%x

Hexadecimal integer
(16진수로출력)

printf(“%x”, 100);

%o

Octal integer (8진수로출력)

printf(“%o”, 100);

%u

Unsigned decimal (양수로출력)

printf(“%u”, 100);

%e

floating point number in
scientific notation

printf(“%e”, 1.234);

%f

floating point number

printf(“%f”, 1.234);

%g

e-format또는 f-format

printf(“%g”, 1.234);

%s

string (문자열)

printf(“%s”, ”C-book”);
3
Use of printf() and scanf()
 The Use of printf() : integer %d
printf(“ %md”, a );
printf(“ %-md”, a);

/*m 정수.오른쪽정렬 */
/*m 정수. 왼쪽정렬 */

[Ex]
a = 12;
printf(“%5d%-5d%dn” ,a, a, a+11);

12^^^^^^1223

– %5d로 출력 : 12^^^
( 5자리에 왼쪽정렬로 출력, 뒤쪽 공간이 남으면 공백으로 채움)
– %-5d로 출력 : ^^^12
( 5자리에 오른쪽정렬로 출력, 앞에 공간이 남으면 공백으로 채움)
– %d로 출력 : 23
(a +11의 값 ‘23’을 그대로 출력)

4
Use of printf() and scanf()
 The Use of printf() : float %f
printf(“ %m.pf”, a );
printf(“ %-m.pf”, a);

/*m, p 정수.오른쪽정렬 */
/*m, p 정수. 왼쪽정렬 */

[Ex]
83.1260^^83.126083.126000^^^83.13
a = 83.126;
printf(“%8.4f%-8.4f%f%-7.2fn”, a, a, a, a );
– %8.4f : 83.1260^
(소수점을 포함 총 8자리에 숫자를 출력하되 소수점 이하 4자리까
지 표시. )
– %-8.4f : ^83.1260
(%8.4f와 동일 , 그러나 음수로 인해 오른쪽으로 정렬)
– %f
: 83.126000
(칸수 제한 없이 소수점 이하 6자로 출력)
– %-7.2f : ^^^83.13
(7자리 확보에 소수점 이하 2자리-반올림, 오른쪽 정렬)
5
Use of printf() and scanf()
 Use of scanf()
– scanf() - key board로부터 data를 입력 받기 위해 사용하는 함수이
다.
scanf(“format string..”, argument list);
%c

character (문자)

scanf(“%c”, &a);

%d

decimal integer (10진수)

scanf(“%d”, &a);

%f

floating point number (float)

scanf(“%f”, &a);

%lf

floating point number (double)

scanf(“%lf”, &a);

%Lf

floating point number (long double)

scanf(“%Lf”, &a);

%s

string (문자열)

scanf(“%s”, &a);

6
Use of printf() and scanf()
[Ex]
#include <stdio.h>
int main() {
int n ;
printf(“Enter number : “);
scanf(“%d”, &n);
printf(“You entered : %d”, n);
return 0;
}

Enter number : 10
You entered : 10
7

Mais conteúdo relacionado

Mais procurados

Modern Effective C++ Item2 Understanding Auto type deducing
Modern Effective C++ Item2 Understanding Auto type deducingModern Effective C++ Item2 Understanding Auto type deducing
Modern Effective C++ Item2 Understanding Auto type deducing건 손
 
코딩인카페 C&JAVA 기초과정 C프로그래밍(2)
코딩인카페 C&JAVA 기초과정 C프로그래밍(2)코딩인카페 C&JAVA 기초과정 C프로그래밍(2)
코딩인카페 C&JAVA 기초과정 C프로그래밍(2)유익아카데미
 
[170327 1주차]C언어 A반
[170327 1주차]C언어 A반[170327 1주차]C언어 A반
[170327 1주차]C언어 A반arundine
 
C언어 연산자에 대해 간과한 것
C언어 연산자에 대해 간과한 것C언어 연산자에 대해 간과한 것
C언어 연산자에 대해 간과한 것jaypi Ko
 
Modern effective c++ 항목 3
Modern effective c++ 항목 3Modern effective c++ 항목 3
Modern effective c++ 항목 3ssuser7c5a40
 

Mais procurados (9)

Modern Effective C++ Item2 Understanding Auto type deducing
Modern Effective C++ Item2 Understanding Auto type deducingModern Effective C++ Item2 Understanding Auto type deducing
Modern Effective C++ Item2 Understanding Auto type deducing
 
코딩인카페 C&JAVA 기초과정 C프로그래밍(2)
코딩인카페 C&JAVA 기초과정 C프로그래밍(2)코딩인카페 C&JAVA 기초과정 C프로그래밍(2)
코딩인카페 C&JAVA 기초과정 C프로그래밍(2)
 
[170327 1주차]C언어 A반
[170327 1주차]C언어 A반[170327 1주차]C언어 A반
[170327 1주차]C언어 A반
 
4. loop
4. loop4. loop
4. loop
 
함수
함수함수
함수
 
C언어 연산자에 대해 간과한 것
C언어 연산자에 대해 간과한 것C언어 연산자에 대해 간과한 것
C언어 연산자에 대해 간과한 것
 
15 3 scanf-기초
15 3 scanf-기초15 3 scanf-기초
15 3 scanf-기초
 
7장매크로
7장매크로7장매크로
7장매크로
 
Modern effective c++ 항목 3
Modern effective c++ 항목 3Modern effective c++ 항목 3
Modern effective c++ 항목 3
 

Semelhante a 2 3. standard io

게임프로그래밍입문 3주차
게임프로그래밍입문 3주차게임프로그래밍입문 3주차
게임프로그래밍입문 3주차Yeonah Ki
 
5 2. string processing
5 2. string processing5 2. string processing
5 2. string processing웅식 전
 
C Language I
C Language IC Language I
C Language ISuho Kwon
 
프로그래밍 및 실습 Chap2
프로그래밍 및 실습 Chap2프로그래밍 및 실습 Chap2
프로그래밍 및 실습 Chap2dktm
 
C수업자료
C수업자료C수업자료
C수업자료koominsu
 
C수업자료
C수업자료C수업자료
C수업자료koominsu
 
DEVIEW-FULL-감독판.pptx
DEVIEW-FULL-감독판.pptxDEVIEW-FULL-감독판.pptx
DEVIEW-FULL-감독판.pptxhanbeom Park
 
파이썬 스터디 2주차
파이썬 스터디 2주차파이썬 스터디 2주차
파이썬 스터디 2주차Han Sung Kim
 
[SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산
[SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산[SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산
[SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산S.O.P.T - Shout Our Passion Together
 
R 프로그래밍 기본 문법
R 프로그래밍 기본 문법R 프로그래밍 기본 문법
R 프로그래밍 기본 문법Terry Cho
 

Semelhante a 2 3. standard io (11)

게임프로그래밍입문 3주차
게임프로그래밍입문 3주차게임프로그래밍입문 3주차
게임프로그래밍입문 3주차
 
5 2. string processing
5 2. string processing5 2. string processing
5 2. string processing
 
C Language I
C Language IC Language I
C Language I
 
프로그래밍 및 실습 Chap2
프로그래밍 및 실습 Chap2프로그래밍 및 실습 Chap2
프로그래밍 및 실습 Chap2
 
Regex
RegexRegex
Regex
 
C수업자료
C수업자료C수업자료
C수업자료
 
C수업자료
C수업자료C수업자료
C수업자료
 
DEVIEW-FULL-감독판.pptx
DEVIEW-FULL-감독판.pptxDEVIEW-FULL-감독판.pptx
DEVIEW-FULL-감독판.pptx
 
파이썬 스터디 2주차
파이썬 스터디 2주차파이썬 스터디 2주차
파이썬 스터디 2주차
 
[SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산
[SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산[SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산
[SOPT] 데이터 구조 및 알고리즘 스터디 - #02 : 스택, 큐, 수식 연산
 
R 프로그래밍 기본 문법
R 프로그래밍 기본 문법R 프로그래밍 기본 문법
R 프로그래밍 기본 문법
 

Mais de 웅식 전

15 3. modulization
15 3. modulization15 3. modulization
15 3. modulization웅식 전
 
15 2. arguement passing to main
15 2. arguement passing to main15 2. arguement passing to main
15 2. arguement passing to main웅식 전
 
12 2. dynamic allocation
12 2. dynamic allocation12 2. dynamic allocation
12 2. dynamic allocation웅식 전
 
12 1. multi-dimensional array
12 1. multi-dimensional array12 1. multi-dimensional array
12 1. multi-dimensional array웅식 전
 
11. array & pointer
11. array & pointer11. array & pointer
11. array & pointer웅식 전
 
10. pointer & function
10. pointer & function10. pointer & function
10. pointer & function웅식 전
 
7. variable scope rule,-storage_class
7. variable scope rule,-storage_class7. variable scope rule,-storage_class
7. variable scope rule,-storage_class웅식 전
 
5 1. character processing
5 1. character processing5 1. character processing
5 1. character processing웅식 전
 
15 1. enumeration, typedef
15 1. enumeration, typedef15 1. enumeration, typedef
15 1. enumeration, typedef웅식 전
 
3 2. if statement
3 2. if statement3 2. if statement
3 2. if statement웅식 전
 
3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib웅식 전
 
2 2. operators
2 2. operators2 2. operators
2 2. operators웅식 전
 
Goorm ide 교육용버전 for skku(학생)
Goorm ide 교육용버전 for skku(학생)Goorm ide 교육용버전 for skku(학생)
Goorm ide 교육용버전 for skku(학생)웅식 전
 
구름 기본 소개자료
구름 기본 소개자료구름 기본 소개자료
구름 기본 소개자료웅식 전
 
Goorm ide 소개 슬라이드(교육용 버전)
Goorm ide 소개 슬라이드(교육용 버전)Goorm ide 소개 슬라이드(교육용 버전)
Goorm ide 소개 슬라이드(교육용 버전)웅식 전
 

Mais de 웅식 전 (20)

15 3. modulization
15 3. modulization15 3. modulization
15 3. modulization
 
15 2. arguement passing to main
15 2. arguement passing to main15 2. arguement passing to main
15 2. arguement passing to main
 
14. fiile io
14. fiile io14. fiile io
14. fiile io
 
13. structure
13. structure13. structure
13. structure
 
12 2. dynamic allocation
12 2. dynamic allocation12 2. dynamic allocation
12 2. dynamic allocation
 
12 1. multi-dimensional array
12 1. multi-dimensional array12 1. multi-dimensional array
12 1. multi-dimensional array
 
11. array & pointer
11. array & pointer11. array & pointer
11. array & pointer
 
10. pointer & function
10. pointer & function10. pointer & function
10. pointer & function
 
9. pointer
9. pointer9. pointer
9. pointer
 
7. variable scope rule,-storage_class
7. variable scope rule,-storage_class7. variable scope rule,-storage_class
7. variable scope rule,-storage_class
 
6. function
6. function6. function
6. function
 
5 1. character processing
5 1. character processing5 1. character processing
5 1. character processing
 
15 1. enumeration, typedef
15 1. enumeration, typedef15 1. enumeration, typedef
15 1. enumeration, typedef
 
3 2. if statement
3 2. if statement3 2. if statement
3 2. if statement
 
3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib
 
2 2. operators
2 2. operators2 2. operators
2 2. operators
 
Goorm ide 교육용버전 for skku(학생)
Goorm ide 교육용버전 for skku(학생)Goorm ide 교육용버전 for skku(학생)
Goorm ide 교육용버전 for skku(학생)
 
구름 기본 소개자료
구름 기본 소개자료구름 기본 소개자료
구름 기본 소개자료
 
Goorm ide 소개 슬라이드(교육용 버전)
Goorm ide 소개 슬라이드(교육용 버전)Goorm ide 소개 슬라이드(교육용 버전)
Goorm ide 소개 슬라이드(교육용 버전)
 
W14 chap13
W14 chap13W14 chap13
W14 chap13
 

2 3. standard io

  • 2. Use of printf() and scanf()  printf()는 Print Format의 약어로, 화면에 내용을 출력할 때 사 용하는 명령(함수)이다. printf(“format string..”, argument list); [Ex] #include <stdio.h> int main() { int n ; n = 25 * 10; printf(“%d”, n); } [Ex] printf(“%c%c%c”, ’a’, ’b’, ’c’ ); printf(“%s”, “def” ); /* 250 이 출력된다. */ /* abc 가 출력된다. */ /* def 가 출력된다. */ 2
  • 3. Use of printf() and scanf()  Conversion characters (format string) %c character (문자) printf(“%c”, ’a’); %d decimal integer (10진수로출력) printf(“%d”, 100); %x Hexadecimal integer (16진수로출력) printf(“%x”, 100); %o Octal integer (8진수로출력) printf(“%o”, 100); %u Unsigned decimal (양수로출력) printf(“%u”, 100); %e floating point number in scientific notation printf(“%e”, 1.234); %f floating point number printf(“%f”, 1.234); %g e-format또는 f-format printf(“%g”, 1.234); %s string (문자열) printf(“%s”, ”C-book”); 3
  • 4. Use of printf() and scanf()  The Use of printf() : integer %d printf(“ %md”, a ); printf(“ %-md”, a); /*m 정수.오른쪽정렬 */ /*m 정수. 왼쪽정렬 */ [Ex] a = 12; printf(“%5d%-5d%dn” ,a, a, a+11); 12^^^^^^1223 – %5d로 출력 : 12^^^ ( 5자리에 왼쪽정렬로 출력, 뒤쪽 공간이 남으면 공백으로 채움) – %-5d로 출력 : ^^^12 ( 5자리에 오른쪽정렬로 출력, 앞에 공간이 남으면 공백으로 채움) – %d로 출력 : 23 (a +11의 값 ‘23’을 그대로 출력) 4
  • 5. Use of printf() and scanf()  The Use of printf() : float %f printf(“ %m.pf”, a ); printf(“ %-m.pf”, a); /*m, p 정수.오른쪽정렬 */ /*m, p 정수. 왼쪽정렬 */ [Ex] 83.1260^^83.126083.126000^^^83.13 a = 83.126; printf(“%8.4f%-8.4f%f%-7.2fn”, a, a, a, a ); – %8.4f : 83.1260^ (소수점을 포함 총 8자리에 숫자를 출력하되 소수점 이하 4자리까 지 표시. ) – %-8.4f : ^83.1260 (%8.4f와 동일 , 그러나 음수로 인해 오른쪽으로 정렬) – %f : 83.126000 (칸수 제한 없이 소수점 이하 6자로 출력) – %-7.2f : ^^^83.13 (7자리 확보에 소수점 이하 2자리-반올림, 오른쪽 정렬) 5
  • 6. Use of printf() and scanf()  Use of scanf() – scanf() - key board로부터 data를 입력 받기 위해 사용하는 함수이 다. scanf(“format string..”, argument list); %c character (문자) scanf(“%c”, &a); %d decimal integer (10진수) scanf(“%d”, &a); %f floating point number (float) scanf(“%f”, &a); %lf floating point number (double) scanf(“%lf”, &a); %Lf floating point number (long double) scanf(“%Lf”, &a); %s string (문자열) scanf(“%s”, &a); 6
  • 7. Use of printf() and scanf() [Ex] #include <stdio.h> int main() { int n ; printf(“Enter number : “); scanf(“%d”, &n); printf(“You entered : %d”, n); return 0; } Enter number : 10 You entered : 10 7