Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Preprocessor directives

\* A program for macro expansion*\


INPUT:
#include<stdio.h>
#define LENGTH 3
#define WIDTH 2
int main()
{
int r,c;
for(r=1; r<=LENGTH; r++)
{
for(c=1; c<=WIDTH; c++)
printf("%d%d",c,r);
printf("\n");
}
return 0;
}

OUTPUT:

\* A program for macro with argument to find the area of a circle*\


INPUT:
#include <stdio.h>
#define PI 3.1415
#define area(r) (PI*(r)*(r))
int main()
{
int radius;
float area;
printf("Enter the radius: ");
scanf("%d",&radius);
area=area(radius);
printf("Area=%.2f",area);

return 0;
}

OUTPUT:

\* A program for endif directive*\


INPUT:
#include<stdio.h>
#define MAX 50
main()
{
#if MAX > 20
printf("Array size is OK");
#endif
}

OUTPUT:

\* A program for else directive*\

INPUT:
#define MAX 50
main()
{
#if MAX > 50
printf("Array size is much large");
#else
printf("Array size is much nominal");
#endif
}

OUTPUT:

\* A program for elif directive*\


INPUT:
#include<stdio.h>
#define PER 60
main()
{
#if PER>=60
printf("First Division");
#elif PER>=50
printf("Second Division");
#elif PER>=40
printf("Third Division");
#else
printf("Fail");
#endif
}

OUTPUT:

\* A program for undef directive*\


INPUT:
#include<stdio.h>
#define ROW 20
#define COL 20
main()
{
int array [ROW][COL];
#undef ROW
#undef COL
}

OUTPUT:

You might also like