027. 조건 연산자 이해하기(?:)027. 조건 연산자 이해하기(?:)

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

main()
{
	int x = 1;
	int y = 2;
	int max;

	max = x > y? x : y;
}

max = x > y? x : y > 5? y : x + y;

//

026. 논리 연산자 이해하기(||, &&, !)026. 논리 연산자 이해하기(||, &&, !)

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

main()
{
	int x = 5;
	int y = 2;

	if( x > 0 && x < 10 )
	{
		printf( "0 > x < 10 \n" );
	}

	if( x < 0 || y == 2 )
	{
		printf( "x가 0보다 작거나, y는 2입니다. \n" );
	}

	if( !(x>y) )
	{
		printf( "x가 y보다 크지 않습니다. \n" );
	}
}
//

025. 관계 연산자 이해하기(<, >, =, >=, <=, !=)025. 관계 연산자 이해하기(<, >, =, >=, <=, !=)

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

main()
{
	int x = 1;
	int y = 2;
	int z = 3;

	if( x == y ) printf( "x는 y와 같습니다. \n" );
	if( x != y ) printf( "x는 y와 같지 않습니다. \n" );
	if( x > y ) printf( "x는 y보다 큽니다. \n" );
	if( x < y ) printf( "x는 y보다 작습니다. \n" );
	if( y >= z ) printf( "y는 z보다 크거나 같습니다. \n" );
	if( y <= z ) printf( "y는 z보다 작거나 같습니다. \n" );
}
//

024. 증감 연산자 이해하기(++, --)024. 증감 연산자 이해하기(++, --)

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

main()
{
	int x = 1;

	printf( "x = %d \n",x++ );		// x = 1이 출력, 그리고 1이 증가
	printf( "x = %d \n",x++ );		// x = 2이 출력, 그리고 1이 증가
	printf( "x = %d \n",++x );		// 1이 먼저 증가, 그리고 x = 4가 출력
	printf( "x = %d \n",x-- );		// x = 4가 출력, 그리고 1이 감소
	printf( "x = %d \n",x-- );		// x = 3이 출력, 그리고 1이 감소
	printf( "x = %d \n",--x );		// 1이 먼저 감소, 그리고 x = 1이 출력
}
//

023. 사칙 연산자 이해하기(+, -, *, /)023. 사칙 연산자 이해하기(+, -, *, /)

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

main()
{
	int x = 4;
	int y = 2;
	int z;

	z = x + y;				// 6 = 4 + 2
	z = x - y;				// 2 = 4 - 2
	z = x * y;				// 8 = 4 * 2
	z = z / y;				// 2 = 4 / 2
	z = (x+y) * (x-y);		// 12 = (4+2) * (4-2)
	z = (x*y) * (x/y);		// 10 = (4*2) + (4/2)
	z = x + y + 2004;		// 2010 = 4 + 2 + 2004
	z = 2004 - x - y;		// 1998 = 2004 - 4 - 2
}
//

022. 부호 연산자 이해하기(+, -)022. 부호 연산자 이해하기(+, -)

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

main()
{
	int x = +4;
	int y = -2;

	printf( " x + (-y) = %d \n", x + (-y) );
	printf( "-x + (+y) = %d \n", -x + (+y) );
}
//

021. 대입 연산자 이해하기(=)021. 대입 연산자 이해하기(=)

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

main()
{
	int x = 1;
	int y = 2;
	int z;
	int zz;

	z = x + y;

	zz = printf( "z의 값 : %d \n",z );
	printf( "zz의 값 : %d \n",zz );
}

이 소스 코드가 재미있는 이유는 zz = printf( "z의 값 : %d \n",z ); 부분 때문이다.

왜냐하면 보통은 printf() 함수의 리턴 값을 생각하지 않기 때문이다.

printf() 함수가 정상적으로 호출 되었다면 출력되는 바이트 수를 리턴한다.

한글은 2byte로 계산하면 zz는 13이 출력된다.

//

020. 문자열형 상수 이해하기(char)020. 문자열형 상수 이해하기(char)

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

#define KOREA "대한민국"
#define BOOK "This is a book"

const char* SOCCOR = "나는 축구를 좋아합니다.";

main()
{
	printf( "문자열형 상수  KOREA의 값 : %s\n",KOREA );
	printf( "문자열형 상수   BOOK의 값 : %s\n",BOOK );
	printf( "문자열형 상수 SOCCOR의 값 : %s\n",SOCCOR );
}
//

019. 논리형 상수 이해하기(bool)019. 논리형 상수 이해하기(bool)

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

#define TRUE 1
#define FALSE 0

main()
{
	if( TRUE )
	{
		printf( "TRUE의 값은 참입니다.\n" );
	}
	else
	{
		printf( "TRUE의 값은 거짓입니다.\n" );
	}

	if( FALSE )
	{
		printf( "FALSE의 값은 참입니다.\n" );
	}
	else
	{
		printf( "FALSE의 값은 거짓입니다.\n" );
	}
}
//

018. 실수형 상수 이해하기(double)018. 실수형 상수 이해하기(double)

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

#define PI 3.141592

const double j = 1.23456789;

main()
{
	PI = 3.141592;
	j = 1.23456789;

	printf( "실수형 상수 PI의 값은 %f\n",PI );
	printf( "실수형 상수 j의 값은 %f\n",j );
}
//