343 views
1 votes
1 votes
PROGRAM 1.

#include<stdio.h>
#define PRINT(x) (x)
#define MACRO(num,str) {\
        printf("\n%d",num);\
        printf(" is");\
        printf(" %s number", str);\
        printf("\n");\
        }
int main()
{  
   
    int num;
    printf("enter num: ");
    scanf("%d",&num);
    if(num & 1)
        MACRO(num,"odd");
    else
        MACRO(num,"even");
    return 0;
}

 

PROGRAM 2.

 

#include<stdio.h>
#define PRINT(x) (x)
#define MACRO(num,str) ({\
        printf("\n%d",num);\
        printf(" is");\
        printf(" %s number", str);\
        printf("\n");\
        })
int main()
{  
   
    int num;
    printf("enter num: ");
    scanf("%d",&num);
    if(num & 1)
        MACRO(num,"odd");
    else
        MACRO(num,"even");
    return 0;
}

2 Answers

1 votes
1 votes
u supposed to put do-while loop i the beginning of macro

that is

#define MACRO(num,str) do{

{\
        printf("\n%d",num);\
        printf(" is");\
        printf(" %s number", str);\
        printf("\n");\
        }while(0);

by putting this our loop execute only one time

on your your way your program is right but try it again by removing #define PRINT(x) (x)

i think it is no need to put in beginning of program.... i am not sure but try once
0 votes
0 votes
in 2nd program u are using () these brackets .

Related questions

4 votes
4 votes
1 answer
4
Shashank Chavan asked Jan 18, 2016
11,219 views
What's the difference between Binary tree height, level and depth? Sometimes it's confusing!Does there definition change according to question also, if mentioned?