initial import
[staff/goc4/2018bti7061.git] / c-6-additional / examples / c-variousexamples / macro2.c
1 #include <stdio.h>
2
3 #define area(x,y) x * y
4
5 #define print(n) int i; for(i=0;i<n;i++){ \
6 printf("%d x %d = %d\n",i,i,i*i);\
7 }
8
9 int main(int argc, char* argv[]){
10
11 int length, width;
12
13 printf("length : ");
14 scanf(" %d",&length);
15 printf("width : ");
16 scanf(" %d",&width);
17 // The constant area is replaced by value length * width
18 printf("Area = %d \n",area(length,width));
19 print(width);
20 }
21 /* Output:
22 bie1@VirtualBox:~/variousExamples$ ./macro2
23 length : 10
24 width : 10
25 Area = 100
26 */