C++ Program to Find Cube of Number using macros

Problem

Write a C++ program to Find Cube of Number using Macros.

Solution

Here’s a sample code snippet demonstrating how you can find the cube of a number in C++ using macros.

#include<iostream>
using namespace std;

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

int main()
{
    int n,cube;

    cout<<"Enter any positive number ";
    cin>>n;

    cube=CUBE(n);

    cout<<"\nThe Cube ="<<cube<<"";

    return 0;
}

Output

C++ Program to Find Cube of Number using macros