본문 바로가기

C 기초/우분투 c

10월 24일

1. #DEFINE 응용 - HAP(CAKE)

Q : x+y, x*y 로 각각 정의하고, h1, h2 를 10과 곱하여 출력하라 

     x = 3, y = 4 

A :

    #include <stdio.h>

    #define CAKE1(x,y) x+y

    #define CAKE2(x,y) (x+y)

 

    int main () {

    int h1 = 0, h2 = 0 ; 

    h1 = 10 * CAKE1(3,4) ; h2 = 10 * CAKE2(3,4) ; 

 

   printf("h1 = %d , h2 = %d ", h1, h2);

 

    return 0;

    }

 

h1 = 34, h2 = 70

 

==============================================

 

2. define, output, count 응용 

Q : output() 을 x로 정의하고, count 를 활용해 3X3 로 나오게 출력하라 

 

A : #include <stdio.h>

    #define output(x) printf("%d %d %d/n" , x##1, x##2, x##3)

    

  int main () {

  int count1=0, count2=0, count3=0, i1=0, i2=0, i3=0 ; 

  count 1 = 1 ; count 2 = 4; count 3 = 5 ; 

  i1 = 2 ; i2 = 3, i3 = 6 

 

 output(count) ; 

 output(i) ; 

 

 return 0;

}

 

==============================================

'C 기초 > 우분투 c' 카테고리의 다른 글

11월 04일  (0) 2019.11.01