Write a Program to find LCM and HCFof 3 numbers in C++ #include<iostream> using namespace std; int lcm(int, int, int); int hcf(int, int, int); int main() { int a,b,c; int LCM, HCF; cout<<“Enter 1st number: “; cin>>a; cout<<“Enter 2nd number: “; cin>>b; cout<<“Enter 3rd number: “; cin>>c; LCM = lcm(a,b,c); HCF = hcf(a,b,c); cout<<“LCM of […]

# Category: cpp codes

## Default Arguments C++: Look at them Closely

We all know what are Default Arguments C++ are, but while playing with them, I found 2 interesting things, many of you might know this but this will be new for freshers and learners. 1-) Look at the following code closely: #include <iostream> // something looks missing void init(int =1, int =2, int =3); […]

## Program to convert Celsius to Fahrenheit in C++

Write a Program to convert Celsius to Fahrenheit in C++. This program is really simple just use the following formula to get the temperature converted into Fahrenheit. Fahrenheit = (1.8 * celsius) + 32 PROGRAM: #include <iostream> using namespace std; int main() { float celsius; float fahrenheit; cout << “Enter Celsius temperature: “; cin […]

## Union and Intersection of Arrays C++

Union and Intersection of Arrays Let us suppose we have two sorted Arrays int Arr1[]={1, 3, 4, 5, 7}; int Arr2[]={2, 3, 5, 6}; then UNION will be: {1, 2, 3, 4, 5, 6, 7} INTERSECTION : {3, 5} C++ Program for UNION of arrays: #include<iostream> #include<stdio.h> using namespace std; /* Function prints union of […]

## Median of two sorted arrays Program C++

What is Median? In probability theory and statistics, a median is described as the number separating the higher half of a sample, a population, or a probability distribution, from the lower half. The median of a finite list of numbers can be found by arranging all the numbers from lowest value to highest value and […]

## Multiple Inheritance in c++ example

What is Multiple Inheritance? Multiple inheritance is a feature of some object-oriented computer programming languages in which an object or class can inherit characteristics and features from more than one parent object or parent class. Deriving directly from more than one class is usually called multiple inheritance. Since it’s widely believed that this concept complicates the […]

## Effective way to Swap two numbers using xor

One of the most effective way to swap two numbers is by using XOR gate. We do not any third variable to store value, therefore it has lower space complexity than the traditional swapping program using third or temporary variable. How it works? To understand this trick, break the statements into unique values: x1 = […]

## Program to Draw Hollow diamond Shape in C++

Wap in C++ to Draw hollow Diamond shape in C++ For other triangle and diamonds shapes see –> Patterns and Shapes in C++ PROGRAM: #include<iostream> using namespace std; int main() { int size; cout<<“Enter size of Diamond: “; cin>>size; int z=1; for ( int i=0; i<=size; i++) { for (int j=size; j>i; j–) { cout<<” […]

## Program to display current Date and Time C++

To show current Date and Time in a program just use “localtime()” function. Calculation of day, month and year is explained. PROGRAM: #include <time.h> time_t theTime = time(NULL); struct tm *aTime = localtime(&theTime); int day = aTime->tm_mday; int month = aTime->tm_mon + 1; // Month is 0 – 11, add 1 to get a jan-dec […]

## C++ Program to find factorial of a Number

What is Factorial of a number? Factorial of a number ‘n’ is the product of all positive integers less than or equal to n, denoted by ‘n!’. For example find factorial of 5. 5! = 5 x 4 x 3 x 2 x 1 = 120 Now let’s see the program to find factorial of a […]