Write a program to find the largest& smallest of three numbers. (Use inline function MAX and MIN)

Image
C++ Programs  Write a program to find the largest& smallest of three numbers. (Use inline function MAX and MIN) Program Code : #include <stdio.h> // macro/inline function to get max of 3 numbers #define MAX(a,b,c) (a > b && a > c ? a : (b > c ? b : c)) // macro/inline function to get min of 3 numbers #define MIN(a,b,c) (a < b && a < c ? a : (b < c ? b : c)) int main() { int x, y, z, large, small;    // accept 3 numbers from console printf("Enter 3 numbers: "); scanf("%d%d%d", &x, &y, &z);   // call inline function to get the max and min of inputed numbers large = MAX(x, y, z); small = MIN(x, y, z);    // print the largest and smallest numbers printf("\nMax between %d, %d, and %d is %d.", x, y, z, large); printf("\nMin between %d, %d, and %d is %d.", x, y, z, small); return 0; } Output :

WAP to illustrate the use of scope resolution operator. Display the various values of the same variables declared at different scope levels.

 C++ Programs 

WAP to illustrate the use of scope resolution operator. Display the various values of the same variables declared at different scope levels.

PROGRAM CODE:


#include<iostream>

using namespace std;

int my_variable = 10; // Global x

int main()

{

 int my_variable = 100; // Local x

 cout << "Value of global my_variable is " << ::my_variable<<endl;

 cout << "Value of local my_variable is " << my_variable<<endl;

 return 0;

}


OUTPUT :



Comments

Popular posts from this blog

Write a program to find the largest& smallest of three numbers. (Use inline function MAX and MIN)

Create a class called employee with the following details as variables within it. 1. Name of the employee (string) 2. Age (int) 3. Designation (string) 4. Salary (double) Write a program to create array of objects for the same to access these. Also, make use of member functions to accept values and print the name, age, designation and salary.

WAP in ++ to generate the Fibonacci series up to user specified limit. Write all the missing terms also at the end.