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 in C++ to swap first and last digits of any number.

 C++ Program 


WAP to swap first and last digits of any number. (For ex:-n=12345, Output:-52341) 

  

CODE:


#include <iostream>

            #include <math.h>

using namespace std;

int main()

{

int n, first, last, sum, digits, nn, a, b;

   cout <<"\n\n Find the number after swapping the first and last digits:\n";

   cout <<"-------------------------------------------------------------\n";

   cout <<" Input any number: ";

   cin >> n;

   digits =(int)log10(n);

   first = n /pow(10, digits);

   last = n %10;

   a = first *(pow(10, digits));

   b = n % a;

   n = b /10;

   nn = last *(pow(10, digits))+(n *10+ first);

   cout <<" The number after swaping the first and last digits are: "<< nn << endl;

}



OUTPUT:





Comments

Popular posts from this blog