Find GCD or HCF of Two Numbers in C++

Ayush Gupta
Updated on 09-Sep-2020 11:43:56

630 Views

In this tutorial, we will be discussing a program to find GCD and HCF of two numbers.For this we will be provided with two numbers. Our task is to find the GCD or HCF (highest common factor) for those given two numbers.Example Live Demo#include using namespace std; int gcd(int a, int b){    if (a == 0)       return b;    if (b == 0)       return a;    if (a == b)       return a;    if (a > b)       return gcd(a-b, b);    return gcd(a, b-a); } int main(){    int a = 98, b = 56;    cout

Find GCD or HCF of Two Numbers Using Middle School Procedure in C++

Ayush Gupta
Updated on 09-Sep-2020 11:40:38

1K+ Views

In this tutorial, we will be discussing a program to find GCD or HCF of two numbers using Middle School Procedure.For this we will be provided with two numbers. Our task is to find the GCD (greatest common divisor) or HCF (highest common factor) for the given values.Example Live Demo#include #define MAXFACTORS 1024 using namespace std; //structure to store factorization typedef struct{    int size;    int factor[MAXFACTORS + 1];    int exponent[MAXFACTORS + 1]; } FACTORIZATION; void FindFactorization(int x, FACTORIZATION* factorization){    int i, j = 1;    int n = x, c = 0;    int k = ... Read More

Find GCD of Floating Point Numbers in C++

Ayush Gupta
Updated on 09-Sep-2020 11:35:58

509 Views

In this tutorial, we will be discussing a program to find GCD of floating point numbers.For this we will be provided with two integers. Our task is to find the GCD (Greatest common divisor) of those two provided integers.Example Live Demo#include using namespace std; //returning GCD of given numbers double gcd(double a, double b){    if (a < b)       return gcd(b, a);    if (fabs(b) < 0.001)       return a;    else       return (gcd(b, a - floor(a / b) * b)); } int main(){    double a = 1.20, b = 22.5;    cout

Find First N Iccanobif Numbers in C++

Ayush Gupta
Updated on 09-Sep-2020 11:33:15

134 Views

In this tutorial, we will be discussing a program to find N lccanobif numbers.For this we will be provided with an integer. Our task is to find the lccanobif number at that position. They are similar to the fibonacci number except the fact that we add the previous two numbers after reversing their digits.Example Live Demo#include using namespace std; //reversing the digits of a number int reverse_digits(int num){    int rev_num = 0;    while (num > 0) {       rev_num = rev_num * 10 + num % 10;       num = num / 10;   ... Read More

Difference Between PermGen Space and Metaspace

Himanshu shriv
Updated on 09-Sep-2020 11:29:52

4K+ Views

PermGen is the memory area for storing class data like static variable, byte code and etc. By default 64 Mb is allocated for PermGen. It can be tuned by using -XXMaxPermSize.In Java 8, PermGen method area replaced with MetaSpace. They have moved permGem to the separate memory in the native OS and that is called MetaSpace. It can by default auto increases its size. In MetaSpace, classes can load and unload during the lifespan of the JVM.Sr. No.KeyPermGenMetaSpace1BasicPermGen is the memory area for storing class data like static variable, byte code and etcIn Java 8, PermGen method area replaced with ... Read More

Find Equation of a Plane Passing Through 3 Points in C++

Ayush Gupta
Updated on 09-Sep-2020 11:29:23

424 Views

In this tutorial, we will be discussing a program to find equation of a plane passing through 3 points.For this we will be provided with 3 points. Our task is to find the equation of the plane consisting of or passing through those three given points.Example Live Demo#include #include #include #include using namespace std; //finding the equation of plane void equation_plane(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3){    float a1 = x2 - x1;    float b1 = y2 - y1;    float c1 = z2 - ... Read More

Difference Between Iterator and Spliterator in Java

Himanshu shriv
Updated on 09-Sep-2020 11:27:40

1K+ Views

Iterator and split iterator both interface are used for iterating over the collection.Split iterator is introduced in Java 8 for achieving parallelism. It can split the given set of element and can perform operation parallely using different independent threads. It can traverse the elements parallely as well as sequentially manner. There are following important methods in the splitIterator interface −trySplit - It is used for split the given set of elements into multiple pieces.tryAdvance - It is equivalent to the hasNext/ next methods available in Iterator interfacegetExactSizeIfKnown  -It is used to get the size of the given set of elements.Sr. ... Read More

Find Cullen Number in C++

Ayush Gupta
Updated on 09-Sep-2020 11:27:30

155 Views

In this tutorial, we will be discussing a program to find Cullen Number.For this we will be provided with an integer. Our task is to find the cullen number at that position using the formula −2n* n + 1Example Live Demo#include using namespace std; //finding the nth cullen number unsigned get_cullen(unsigned n){    return (1

Difference Between Intermediate and Terminal Operations in Java 8

Himanshu shriv
Updated on 09-Sep-2020 11:25:15

16K+ Views

Stream is introduced in Java 8, it is only used for processing group of data not for the storting elements.. It does not modify the actual collection, they only provide the result as per the pipelined methods.Stream api supports multiple operations and operations are divided into two parts −Intermediate Operation- These operations are used to pipeline other methods and to transform into the other streams. They don’t produce results because these operation does not invoke until the terminal operation gets executed. Below are the examples −sorted(Comparator)peek(Consumer)distinct()Terminal operations - These operations are used to produce results. They can’t be used for ... Read More

Find Covariance in C++

Ayush Gupta
Updated on 09-Sep-2020 11:25:14

728 Views

In this tutorial, we will be discussing a program to find covariance.For this we will be provided with two sets of random variables. Our task is to calculate their covariance i.e, the measure of how much those two values differ together.Example Live Demo#include using namespace std; //function to find mean float mean(float arr[], int n){    float sum = 0;    for(int i = 0; i < n; i++)    sum = sum + arr[i];    return sum / n; } //finding covariance float covariance(float arr1[], float arr2[], int n){    float sum = 0;    for(int i = 0; i ... Read More

Advertisements