[go: up one dir, main page]

0% found this document useful (0 votes)
13 views2 pages

Program List Chapter 1

The document contains several C programming exercises, including finding the minimum of two numbers, displaying the first five natural numbers, calculating the area of a square, and demonstrating the use of preprocessor directives like #if and #define. Each exercise is accompanied by a code snippet and its expected output. Additionally, it lists further tasks for writing C programs involving maximum number display, number-to-word conversion, and simple interest calculation using macros.

Uploaded by

gkuntalwad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

Program List Chapter 1

The document contains several C programming exercises, including finding the minimum of two numbers, displaying the first five natural numbers, calculating the area of a square, and demonstrating the use of preprocessor directives like #if and #define. Each exercise is accompanied by a code snippet and its expected output. Additionally, it lists further tasks for writing C programs involving maximum number display, number-to-word conversion, and simple interest calculation using macros.

Uploaded by

gkuntalwad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

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.

You might also like