728x90

1. ๋‹จ์–ด ์ถœ๋ ฅ

  • C์–ธ์–ด์—์„œ ์ถœ๋ ฅ์˜ ๊ฒฝ์šฐ printf๋ผ๋Š” ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉ
  • printf ํ•จ์ˆ˜ ์•ˆ์— ๋ฌธ์ž์—ด์„ ๋„ฃ๊ฒŒ ๋˜๋ฉด, ํ•ด๋‹น ๋ฌธ์ž์—ด์ด ํ™”๋ฉด์— ์ถœ๋ ฅ
  • ๋ฌธ์ž์—ด์€ ํฐ๋”ฐ์˜ดํ‘œ๋ฅผ ์ด์šฉํ•˜์—ฌ ํ‘œํ˜„
  • printf ํ•จ์ˆ˜๋Š” stdio.h ๋ผ๋Š” ํ—ค๋”๋ฅผ ์ฝ”๋“œ ์ƒ๋‹จ์— ํฌํ•จ์‹œ์ผœ์•ผ ์‚ฌ์šฉ๊ฐ€๋Šฅ
printf("Hello");

 

โ–ถ ๋ฌธ์ œ: Hello๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•ด๋ณด์„ธ์š”.

#include <stdio.h>

int main() {
    printf("Hello");
    return 0;
}

2. ๋ฌธ์žฅ ์ถœ๋ ฅ

  • C์—์„œ ๋ฌธ์žฅ์„ ์ถœ๋ ฅํ•  ๋•Œ๋Š”, ํฐ๋”ฐ์˜ดํ‘œ๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•œ๋‹ค.
printf("Hello World!");

 

โ–ถ๋ฌธ์ œ: Hello World! ๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•ด๋ณด์„ธ์š”.

#include <stdio.h>

int main() {
    printf("Hello World!");
    return 0;
}

3. ๋”ฐ์˜ดํ‘œ ์ถœ๋ ฅ

  • ๋ฌธ์ž์—ด์— "๋ฅผ ๋ฌธ์ž๋กœ์„œ ํฌํ•จ์‹œํ‚ค๊ธฐ ์œ„ํ•ด์„œ๋Š” ํ•ด๋‹น ๋ฌธ์ž ์•ž์— \๋ฅผ ๋ถ™์—ฌ์•ผ ํ•œ๋‹ค.
#include <stdio.h>

int main() {
    printf("\"Hello\"");
    return 0;
}

 

โ–ถ๋ฌธ์ œ: He says "It's a really simple sentence". ๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•ด๋ณด์„ธ์š”.

#include <stdio.h>

int main() {
    printf("He says \"It's a really simple sentence\".");
    return 0;
}

4. 2์ค„ ์ถœ๋ ฅ

  • c์—์„œ ์ค„๋ฐ”๊ฟˆ์„ ์ถœ๋ ฅํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š”, \n ๋ฌธ์ž๋ฅผ ์ด์šฉ
  • \n ๋ฌธ์ž๋Š” new line์„ ์˜๋ฏธํ•˜๋Š” ํŠน์ˆ˜๋ฌธ์ž๋กœ, ํ•œ ์ค„์„ ๋ˆ๋‹ค๋Š” ๊ฒƒ์„ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค.
#include <stdio.h>

int main() {

	printf("Hello World");
	printf("\n");
	printf("C is Fun");

	return 0;

}
#include <stdio.h>

int main() {

	printf("Hello World\nC is Fun");

	return 0;

}

 

โ–ถ๋ฌธ์ œ:

Hello
World

 

๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•ด๋ณด์„ธ์š”.

#include <stdio.h>

int main() {
    printf("Hello\nWorld");
    return 0;
}

5. ์ˆซ์ž ์ถœ๋ ฅํ•˜๊ธฐ

  • printf ๋ฅผ ์ด์šฉํ•˜์—ฌ ์ˆซ์ž(int)๋ฅผ ์ถœ๋ ฅํ•ด์ฃผ๋ ค๋ฉด " "๋ฌธ์ž์—ด ๋‚ด์— ๋ณ€์ˆ˜ ํฌ๋งท %d ๋ฅผ ์ง€์ •ํ•ด์ฃผ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
  •  printf("%d", ํฌ๋งท์— ๋Œ€์‘ํ•˜๋Š” ์ˆซ์ž ๋ณ€์ˆ˜)
#include <stdio.h>

int main() {
	printf("%d", 3);
	return 0;
}
#include <stdio.h>

int main() {
	printf("3");
	return 0;
}

 

โ–ถ๋ฌธ์ œ: ์ˆซ์ž 3์„ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.

#include <stdio.h>

int main() {
    printf("%d",3);
    return 0;
}

6. ์ˆซ์ž 2๊ฐœ ์ถœ๋ ฅ

  • 2๊ฐœ์˜ ๊ฐ’์„ ๊ณต๋ฐฑ์„ ์‚ฌ์ด์— ๋‘๊ณ  ์ถœ๋ ฅํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” printf ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•ด " " ๋ฌธ์ž์—ด ๋‚ด ๋‘ ๊ฐ’์„ ๊ณต๋ฐฑ์„ ์‚ฌ์ด์— ๋‘๊ณ  ์ถœ๋ ฅํ•ด์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.
#include <stdio.h>

int main() {
	printf("3 5");
	return 0;
}
  • ์ˆซ์ž๊ฐ€ ๋‘๊ฐœ์ด๋ฏ€๋กœ, ์ˆซ์ž ๋ณ€์ˆ˜ ํฌ๋งท %d๋ฅผ ๋‘๊ฐœ ์จ์ฃผ๊ณ , ์ค‘๊ฐ„์— ๊ณต๋ฐฑ์„ ๋„ฃ์–ด์ค๋‹ˆ๋‹ค. ๊ฐ๊ฐ์˜ ์ˆซ์ž๋Š” ์ˆœ์„œ๋Œ€๋กœ ํ•ด๋‹น ์œ„์น˜์˜ ๋ณ€์ˆ˜ ํฌ๋งท์— ๋Œ€์‘๋ฉ๋‹ˆ๋‹ค.
#include <stdio.h>

int main() {
	printf("%d %d", 3, 5);
	return 0;
}

 

โ–ถ๋ฌธ์ œ: ์ˆซ์ž 3๊ณผ 5๋ฅผ ๊ฐ๊ฐ ๊ณต๋ฐฑ์„ ์‚ฌ์ด์— ๋‘๊ณ  ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•ด๋ณด์„ธ์š”.

#include <stdio.h>

int main() {
    printf("%d %d",3,5);
    return 0;
}

7. ํ•œ์ค„ ์ถœ๋ ฅ

โ–ถ๋ฌธ์ œ: Let's go LeebrosCode!๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•ด๋ณด์„ธ์š”.

#include <stdio.h>

int main() {
    printf("Let's go LeebrosCode!");
    return 0;
}

8. ๋‘์ค„ ์ถœ๋ ฅ

โ–ถ๋ฌธ์ œ:

Hello students!
Welcome to LeebrosCode!

๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•ด๋ณด์„ธ์š”.

#include <stdio.h>

int main() {
    printf("Hello students!\n");
    printf("Welcome to LeebrosCode!");
    return 0;
}

9. ๋‹ค์–‘ํ•˜๊ฒŒ ์ถœ๋ ฅ

โ–ถ๋ฌธ์ œ:

Total days in Year
365
Circumference rate
3.1415926535

๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•ด๋ณด์„ธ์š”.

#include <stdio.h>

int main() {
    printf("Total days in Year\n");
    printf("%d\n",365);
    printf("Circumference rate\n");
    printf("3.1415926535");
    return 0;
}

+ Recent posts