C/C++ Program for Finding square of the given number & greatest of the two number through MACRO FUNCTIONS IN C++

Leave a Comment
/*  The following C++ program, in ANSI Standard, defines two macro function namely for squaring & finding max of the two numbers. In both the two cases the user inputs data & the macro function process the data & returns it. The purpose of MACRO function is to improve the speed of the program by reducing the wastage of time in calling function again & again .These function are  defined by using (#) preprocessor directive . All the call statements to a macro function will be  replaced by its code during compile time.*/


#include<iostream.h>
#include<stdlib.h>   
//For system("pause") function
#define sqr(a)    (n*n)    //Macro For Squaring the function
#define max(a,b) (a>b?a:b)  //Macro for finding the greatest of the two
int main()
{
 int x1,y1,ans1;
 clrscr();
 cout<<"Enter two no (Add Space As A Seperator): " ;
 cin>>x1>>y1; 
//performing (x1>y1?x1:y1)
 ans1 =max(x1,y1);
 cout<<"\nMaximum Of the 2 numers is " <<ans1 <<endl;
 int n,ans2;
 cout<<"\nEnter  number to square :" ;
 cin>>n;
 ans2=sqr(n);  
//  performing (n*n)
 cout<<"Square of the given number is  " <<ans2<<endl;
 system("pause");
 return 0;
}


ScreenShots:
C/C++ Program for Finding square of the given number & greatest of the two number through MACRO FUNCTIONS IN C++
Screen Shot of C/C++ Program for Finding square of the given number & greatest of the two number through MACRO FUNCTIONS IN C++
 

0 comments: