1. 한장정리
# include <stdio.h> // standard input output 등 기본적인 입출력
// 정수형 변수
/* 주석 길게 달라면
이렇게
*/
int main(void)
{
int age = 12; //자료 형을 쓰고나서 변수 선언
printf("%d\n", age); // %d d에 위에 오는 정수 선언, 파이썬과 같음
age = 21; // (변수를 수정할때) age를 다시 쓴다면 int 선언 안해도됨
printf("%d\n", 1);
printf("%d", 2); // \n을 붙이지 않는다면 다음 실행결과와 결과값이 붙어서 나옴
printf("%d\n", 3);
// 실수형 변수에 대한 예제
float f = 46.5f;// 실수형 변수는 뒤에 f를 붙여야함
printf("%f\n",f)
// 만약 소수점 뒤 숫자들을 절산하고 싶으면 "%.2f\n" < 소수둘째짜리까지만
double d //얘는 뭐하는애인지 이해못함
// 상수
const int YEAR = 2000; //상수 선언을 해주면 이후에 YEAR는 수정 못함
// printf ?
// 연산
int add = 3 + 7;
// printf("3+7= %d\n", add);
printf("%d + %d = %d\n", 3, 7, 3 + 7);
// scanf < 키도브 입력을 받아서 저장
int input; // input이라는 변수가 있다고 가정
printf("값을 입력하세요:");
scanf_s("%d test", &input); // 여기서 변수값을 받아주는 셈
printf("입력값 : %d\n", input);
// 파이썬과 다른점은 파이썬의 경우 print()
int one, two, three;
scanf_s("%d %d %d", &one, &two ,&three);
printf("첫번째 값: %d\n두번째 값 :%d\n세번째 값:%d\n", one, two, three);
// 문자(한 글자), 문자열(그 이상)
char c = 'A';
//문자열
char str[256]; //큰 공간을 만드는구나~
scanf_s("%s", str, sizeof(str)); // 256자 미만으로 받겠다 선언,문자열의 경우 s
printf("%s\n", str);
return 0;
}
2. C언어의 input 기능
int one, two, three;
scanf_s("%d %d %d", &one, &two ,&three);
printf("첫번째 값: %d\n두번째 값 :%d\n세번째 값:%d\n", one, two, three);
PS. 그리고 비교를 위한 파이썬 input 문법
https://www.codingfactory.net/10085
아무래도 파이썬이 더 직관적이긴 하네요
댓글