본문 바로가기

수업과제

2024000303김현진5주차

#include <stdio.h>
int main()

 

{
printf("나이 : 20\n");
printf("나이 : %d\n", 20);
return 0;
}
printf의 기본 사용법

#include <stdio.h> // 표준 입출력 헤더 파일 포함
int main()
{
// 첫 번째 printf 함수: 직접 문자열 안에 값을 넣어 출력
printf("이름 : ㅏㅎ하하 나이 : 20 키 : 175.5\n");
 
// 두 번째 printf 함수: 서식 지정자를 사용하여 변수의 값을 문자열에 포함시켜 출력
printf("이름 : %s 반 : %c 나이 : %d 키 : %lf\n", "ㅏㅎ하하",'B',20, 175.5 );
return 0; // 프로그램 정상 종료
}

 


 

 

 

 

 

#include <stdio.h>
int main()
{
printf("%05d", 12);
return 0;
}

총 3칸 띄어짐('000'12)

 

#include <stdio.h>
int main()
{
printf("%-5daaaaaaaaa", 12);
return 0;
}

 

 

 

 

#include <stdio.h>
int main()
{
printf("%+d %d", 12,12);
return 0;
}

 

 

 

 

#include <stdio.h>
int main()
{
printf("%.2lf", 12.3456);
return 0;
}

 

 

소수점 2자리(%.'2'f)까지 반올림

 

#include <stdio.h>
int main(void)
{
printf("123456789012345678901234\n");
printf("%d%d%d\n", 100, -200, 300);
printf("%d %d %d\n", 100, -200, 300);
printf("%-8d%-8d%-8d\n", 100, -200, 300);
printf("%+8d%8d%8d\n", 100, -200, 300);
printf("%5d,%05d\n", 100, 100);
return 0;
}

 

#include <stdio.h>
int main(void)
{
printf("%f\n", 100.789);
printf("%e\n", 100.789);
printf("%g\n", 100.789);
printf("%5.1f\n", 100.789);
return 0;
}

 

 

 

 

 

 

 

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void)
{
int c;
printf("당신의 나이를 입력하세요 ");
scanf("%d",&c); // 사용자로부터 문자 입력 받기
printf("당신의 나이는 \"%d\"세입니다\n", c);
return 0;
}

 

 

 

 

 

 

 

출처 : SmileHan의 c프로그래밍

'수업과제' 카테고리의 다른 글

2024000303김현진7주차  (0) 2024.04.16
2024000303김현진6주차  (0) 2024.04.09
2024000303김현진4주  (0) 2024.03.26
2024000303김현진3주차  (0) 2024.03.19
김현진 2주차수업  (0) 2024.03.12