Computer Science, asked by laukikjain471, 1 year ago

Write a program to find out square and cube of given number using macros.

Answers

Answered by aryanrckz
6

/**

* C program to find square and cube of a number using macro

*/

#include <stdio.h>

// Define macro to find square and cube

#define SQUARE(x) (x * x)

#define CUBE(x) (x * x * x)

int main()

{

int num;

// Input a number from user

printf("Enter any number to find square and cube: ");

scanf("%d", &num);

// Calculate and print square

printf("SQUARE(%d) = %d\n", num, SQUARE(num));

// Calculate and print cube

printf("CUBE(%d) = %d\n", num, CUBE(num));

return 0;

}

Answered by roopa2000
0

Answer:

Describe macros using an example.

A macro is a single computer command that executes a number of tasks simultaneously. Using Excel VBA to construct multi-function instructions in the Microsoft software Excel is an illustration of a macro.

/**

* C program to find square and cube of a number using macro

*/

#include <stdio.h>

// Define macro to find square and cube

#define SQUARE(x) (x * x)

#define CUBE(x) (x * x * x)

int main()

{

int num;

// Input a number from user

printf("Enter any number to find square and cube: ");

scanf("%d", &num);

// Calculate and print square

printf("SQUARE(%d) = %d\n", num, SQUARE(num));

// Calculate and print cube

printf("CUBE(%d) = %d\n", num, CUBE(num));

return 0;

}

Similar questions