Found 7347 Articles for C++

Program to find first N Iccanobif Numbers in C++

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

70 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

Program to find equation of a plane passing through 3 points in C++

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

292 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

Program to find Cullen Number in C++

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

119 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

Program to find covariance in C++

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

542 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

Program to find count of numbers having odd number of divisors in given range in C++

Ayush Gupta
Updated on 09-Sep-2020 11:22:36

269 Views

In this tutorial, we will be discussing a program to find the count of numbers having odd number of divisors in a given range.For this we will be provided with the upper and lower limits of the range. Our task is to calculate and count the number of values having an odd number of divisors.Example Live Demo#include using namespace std; //counting the number of values //with odd number of divisors int OddDivCount(int a, int b){    int res = 0;    for (int i = a; i

Program to find correlation coefficient in C++

Ayush Gupta
Updated on 09-Sep-2020 11:20:26

2K+ Views

In this tutorial, we will be discussing a program to find correlation coefficient.For this we will be provided with two arrays. Our task is to find the correlation coefficient denoting the strength of the relation between the given values.Example Live Demo#include using namespace std; //function returning correlation coefficient float find_coefficient(int X[], int Y[], int n){    int sum_X = 0, sum_Y = 0, sum_XY = 0;    int squareSum_X = 0, squareSum_Y = 0;    for (int i = 0; i < n; i++){       sum_X = sum_X + X[i];       sum_Y = sum_Y + Y[i];   ... Read More

Program to find compound interest in C++

Ayush Gupta
Updated on 09-Sep-2020 11:17:09

241 Views

In this tutorial, we will be discussing a program to find compound interest.Compound interest is the interest by adding the current interest to the principal sum and then calculating the interest on the updated amount.Example Live Demo#include using namespace std; int main(){    double principle = 10000, rate = 10.25, time = 5;    //calculating compound interest    double CI = principle * (pow((1 + rate / 100), time));    cout

Shortest Majority Substring in C++

Arnab Chakraborty
Updated on 02-Sep-2020 12:29:34

247 Views

Suppose we have a lowercase alphabet string s, we have to find the length of the shortest substring (minimum length is 2) such that some letter appears more than the other letters combined. If we cannot find any solution, then return -1.So, if the input is like "abbbcde", then the output will be 2, the substring "bb" has minimum length and this appears more than other letters.To solve this, we will follow these steps −Define a function ok(), this will take an array cnt, total := 0, maxVal := 0for each element it in cnt, dototal := total + itmaxVal ... Read More

Rotate List Left by K in C++

Arnab Chakraborty
Updated on 02-Sep-2020 12:27:11

267 Views

Suppose we have a list of numbers. We have to define a method that can rotate a list of numbers to the left by k elements.So, if the input is like [5, 4, 7, 8, 5, 6, 8, 7, 9, 2], k = 2, then the output will be [8, 5, 6, 8, 7, 9, 2, 5, 4, 7]To solve this, we will follow these steps −Define an array retn := size of numsk := k mod nfor initialize i := k, when i < n, update (increase i by 1), do −insert nums[i] at the end of retfor initialize ... Read More

Minimum Size of Two Non-Overlapping Intervals in C++

Arnab Chakraborty
Updated on 02-Sep-2020 12:24:36

196 Views

Suppose we have a list of intervals where each interval contains the [start, end] times. We have to find the minimum total size of any two non-overlapping intervals, where the size of an interval is (end - start + 1). If we cannot find such two intervals, return 0.So, if the input is like [[2, 5], [9, 10], [4, 6]], then the output will be 5 as we can pick interval [4, 6] of size 3 and [9, 10] of size 2.To solve this, we will follow these steps −ret := infn := size of vsort the array v based ... Read More

Advertisements