Q1) Write a c program to check minimum number between two
numbers .
#include <stdio.h>
#define MIN(x, y) ((x) < (y) ? (x) : (y))
int main()
{
int n1 = 5;
int n2 = 10;
int min_numb = MIN(n1, n2);
printf("The minimum number between %d and %d is %d\n", n1, n2,
min_numb);
return 0;
}
Q2) Write a c program to display first 5 natural numbers.
#include <stdio.h>
// defining a macros
#define n 5
int main()
{
printf("Counting...");
for (int i = 1; i <= n; i++) {
printf("\n%d ",i);
}
return 0;
}
Q3) Write a c program to calculate area of square .
#include <stdio.h>
// calc area of square
#define area(side) (side * side)
int main()
{
int side=10;
printf("Area of square is: %d", area(side));
return 0;
}
Q4) Write a c program to show use of #if,#define macros.
#include <stdio.h>
#define DEBUG
#define VERSION 2
int main() {
#ifdef DEBUG
printf("Debugging is enabled.\n");
#endif
#ifndef RELEASE
printf("Release mode is not enabled.\n");
#endif
#if VERSION == 1
printf("Version 1 of the software.\n");
#elif VERSION == 2
printf("Version 2 of the software.\n");
#else
printf("Unknown version.\n");
#endif
return 0;
}
Output
Debugging is enabled.
Release mode is not enabled.
Version 2 of the software.
Howwork
1) Write a c program to display maximum number from given number
use pre-processor concept.
2) Write a c program to accept a number from user (1 to 5 range) and
display number in word.
3)Write a c program to calculate simple interest using macros.