#include <stdio.h>
void main1() {
printf("자료형과 변수를 이용한 printf()함수 연습 프로그램 \n");
//정수형
short short_value = 100;
int int_value = 1234;
long long_value = 300L;
unsigned int unit_value = 400;
printf("short = %d, int=%d, long = %ld, unsigned int %u\n", short_value, int_value, long_value, unit_value);
printf("8진수=%o, 16진수=%x\n", short_value, short_value);
printf("%d\n", int_value);
printf("%6d\n", int_value);
printf("%+d\n", int_value);
printf("%+6d\n", int_value);
printf("%06d\n", int_value);
//실수형
float float_value = 12.34f;
double double_value = 123.456;
printf("float=%f, double=%lf\n", float_value, double_value);
printf("%f\n",float_value);
printf("%7.1f\n", float_value);
printf("%+7.2f\n", float_value);
printf("%7.3f\n", float_value);
printf("%07.2f\n", float_value);
//문자형
char char_value_1 = 65;
char char_value_2 = 'B';
printf("char =%c, char=%d\n", char_value_1, char_value_2);
//문자열
char* string_value = "C Program";
printf("%s\n", string_value);
printf("%10s\n", string_value);
printf("%-10s\n", string_value);
}
#include <stdio.h>
int main()
{
int int_input;
printf("Input int > ");
scanf_s("%d", &int_input);
printf("int = %d\n", int_input);
float float_input;
printf("Input float > ");
scanf_s("%f", &float_input);
printf("float = %f\n", float_input);
getchar();
char char_input;
printf("Input char > ");
scanf_s("%c", &char_input, sizeof(char));
printf("char = %c\n", char_input);
char char_string[20];
printf("Input String > ");
scanf_s("%s", char_string, sizeof(char_string));
printf("string = %s\n", char_string);
}
3개의 정소를 입력받아서 출력하는 프로그램
#include <stdio.h>
int main()
{
int int_1, int_2, int_3;
printf("정수값 3개를 입력하세요 > ");
scanf_s(" %d %d %d", &int_1, &int_2, &int_3);
printf("첫번째 입력값은 %d\n", int_1);
printf("두번째 입력값은 %d\n", int_2);
printf("세번째 입력값은 %d\n", int_3);
}
printf()함수 : 표준 출력에 표시하고자 하는 내용을 출력해 주는 기능ㅎ을 가진 함수
형식지정자 :
-변수나 상수의 값을 문자열로 변환하여 화면에 출력할 수 있게 함
-%로 시작하며, 자료형에 따라 지정되어 있음
-정수형자릿수 지정 - 정수형 형식 : %(+/-)(0)(전체자리수)d
-실수형자릿수 지정 - 실수형 형식 : %(+/-)(0)(전체자리수.소수점자릿수)f
-문자열자릿수 지정 - 문자열 형식 : %(-)(전체자리수)s
제어문자 : 역슬래시로 시작됨(화면에는 \로 표시됨)
scanf_s()함수 : 데이터를 표준입력에서 입력받을 때 사용하는 함수
sizeof()함수 : 변수, 상수, 자료형에 대한 자료형의 크기를 반환해 주는 함수