C/본수업

[2025.03.10] Ch.02_C 첫걸음_연습문제

polibo 2025. 3. 10. 15:25

★ 문제 1

  • 다음과 같이 출력되는  프로그램을 작성하라.
  • 첫 번째 출력문 : Gustav Mahler
  • 두 번째 출력문 : Gustav 다음 줄 Mahler
  • 세 번째 출력문 : Gustav
  • 네 번째 출력문 : Mahler
// 문제 1
#include <stdio.h>

int main()
{
    printf("Gustav Mahler\n");
    printf("Gustav\nMahler\n");
    printf("Gustav ");
    printf("Mahler\n");

    return 0;
}

 

 

 

★ 문제 2

  • 자신의 이름과 주소를 출력하는 프로그램을 작성하라.
// 문제 2
#include <stdio.h>

int main()
{
    printf("내 이름은 Polibo 이구요\n저는 한국에 살아여~\n");
    return 0;
}

 

 

 

★ 문제 3

  • 햇수로 된 자신의 나이를 날짜로 환산하고, 두 값을 모두 출력하는 프로그램을 작성하라.
  • 이때, 개월이 모자라는 해와 윤년은 무시하라.
// 문제 3
#include <stdio.h>

int main()
{
    int year_age = 26;
    int date_age = 365 * year_age;

    printf("햇수 나이 : %d, 날짜 나이 : %d\n", year_age, date_age);

    return 0;
}

 

 

 

★ 문제 6

  • toes라는 정수형 변수를 사용하는 프로그램을 작성하라.
  • 프로그램은 toes를 10으로 설정한다. 또한 toes의 2배는 얼마이고, toes의 제곱은 얼마인지 계산한다.
  • 그러고 나서 세 값을 구분하여 출력한다.
// 문제 6
#include <stdio.h>

int main()
{
    int toes = 10;

    printf("toes = %d\ntoes의 2배 = %d\ntoes의 제곱 = %d\n", toes, 2*toes, toes*toes);

    return 0;
}