C

[C] 053 정수값 입력받기 scanf()

qkrwngus 2021. 1. 24. 17:03

Desc :

 

int scanf(const char *format [,argument].....);

 

정수 값을 읽기 위한 tmp변수는 값이 아닌 번지를 넘겨주어야한다(&사용)


Source Code :

#include <stdio.h>

void main()
{
	int count;
	int tmp;
	int total = 0;

	for (count = 1; count <= 3; count++)
	{
		printf("%d번째 정수값을 입력한 후 Enter키를 누르세요\n", count);

		scanf("%d", &tmp);

		total += tmp;

		printf("입력값 = %d,총 합 = %d\n", tmp, total);
	}

	printf("읽은 정수의 총 합은 %d입니다.\n", total);
}

 


Result :