Posts

Showing posts from May, 2021

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 :

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.

Image
 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 :

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.

Image
  C++ Programs 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.            PROGRAM CODE: #include<iostream> using namespace std;       class Employee       {              char Name[25];              int Age;              char Desg[8];              long Salary;          ...

WAP in C++ to input a matrix of dimension m*n. If base address is 1000. Find the address of (m-1, n-1) element of the matrix.

Image
  C++ Programs WAP to input a matrix of dimension m*n. If base address is 1000. Find the address of (m-1, n-1) element of the matrix. PROGRAM CODE: #include<iostream> using namespace std;   int main()       {              int b,i,j,w,lr=0,lc=0,n,m;              int a[10][10];              cout<<"enter the no. of rows in matrix - ";              cin>>m;              cout<<"enter no. of columns in matrix - ";              cin>>n;              cout<<"enter the elements in matrix - ";              for(i=0;i<m;i++)              {                       for(j=0;j<n...

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

Image
  C++ Programs WAP to generate the Fibonacci series up to user specified limit. Write all the missing terms (e.g. 4, 6, 7, 9, 10, 11, 12, 14, 15…) also at the end. PROGRAM CODE:    #include<iostream> using namespace std; int main() {             int n,c,first=0,second=1,next;             int a[20],i,j=0,count=0;             cout<<"Enter the no. of terms of Fibonacci series=";             cin>>n;             cout<<"Terms of Fibonacci series are"<<endl;             for(c=0;c<n;c++)             {            ...

WAP in C++ to swap first and last digits of any number.

Image
  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 ...

WAP in C++ to find average marks of five subjects of a student in a class.

Image
C++ Program  WAP to find average marks of five subjects of a student in a class. CODE: #include <iostream> using namespace std;             int main(){     int subjects, i;      float marks, total=0.0f, averageMarks, percentage;    // Input number of subjects     cout << "Enter number of subjects\n";      cin >> subjects;          // Take marks of subjects as input     cout << "Enter marks of subjects\n";         for(i = 0; i < subjects; i++){        cin >> marks;        total += marks;     }          // Calculate Average     averag...

Popular posts from this blog

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

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

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.