053. 정수값 입력받기(scanf)053. 정수값 입력받기(scanf)

Posted at 2010. 11. 22. 04:45 | Posted in Computer/초보자를 위한 C 언어 300제
#include <stdio.h>

void main( void )
{
	int count;		// 3회를 카운트하기 위한 변수
	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 );
}
//

052. 문자 출력하기(putch)052. 문자 출력하기(putch)

Posted at 2010. 11. 22. 04:42 | Posted in Computer/초보자를 위한 C 언어 300제
#include <stdio.h>
#include <conio.h>

int print( char *string );

void main( void )
{
	print( "This is a putch function!" );
}

int print( char *string )
{
	int len = 0;

	while( *string != (char)NULL )
	{
		putch( *string );
		string++;
		len++;
	}

	// 현재 출력되고 있는 줄을 다음 줄의 첫 번째로 이동
	putch( '\r' );		// 캐리지 리턴
	putch( '\n' );		// 라인 피드

	return len;
}
//

051. 문자 입력받기(getch)051. 문자 입력받기(getch)

Posted at 2010. 11. 22. 04:39 | Posted in Computer/초보자를 위한 C 언어 300제
#include <stdio.h>
#include <conio.h>

#define ENTER 13

void main( void )
{
	int ch;

	printf( "아스키 코드로 변환할 키를 누르세요...\n" );
	printf( "Enter 키를 누르면 프로그램은 종료됩니다.\n" );

	do
	{

		ch = getch();

		printf( "문자 : (%c) , 아스키 코드 = (%d)\n", ch, ch );

	} while( ch != ENTER );
}
//