Found 7347 Articles for C++

Find if a molecule can be formed from 3 atoms using their valence numbers in C++

Arnab Chakraborty
Updated on 17-Dec-2019 10:51:32

44 Views

As we know the valance number is the number that defines how-many bonds the atom must form with other atoms. We have the valance numbers of three atoms. We have to check whether they can make one molecule or not. Atoms can form multiple bonds with each other. So if the valance numbers are 2, 4, 2, then the output will be YES. As the bonds are like below −1 – 2, 1 – 2, 2 – 3, 2 – 3.Suppose the valance numbers are a, b and c. Consider c is largest. Then we have two cases in which ... Read More

Find i’th index character in a binary string obtained after n iterations in C++

Arnab Chakraborty
Updated on 17-Dec-2019 10:46:00

161 Views

Suppose we have a binary string bin. Then apply n iterations on it, and in each iteration 0 becomes 01 and 1 becomes 10, after that ith index character in the string after nth iteration. So if the binary string is 101, and n = 2, and i = 3, so after first iteration it will be 100110, in the next iteration, it will be 100101101001, so ith index is holding 1.To solve this, we have to follow these steps −Run loop n times, and in each iteration run another loop on the stringConvert each character of binary string, and ... Read More

Find height of a special binary tree whose leaf nodes are connected in C++

Arnab Chakraborty
Updated on 17-Dec-2019 10:40:20

146 Views

Suppose we have a special binary tree, whose leaf nodes are connected to form a circular doubly linked list. We have to find its height. So the left pointer of the left most leaf will act as previous pointer of circular doubly linked list, and its right pointer will act as next pointer of the linked list.In this case the height finding strategy is similar to the normal binary search tree. We recursively calculate the height of the left and right subtrees of a node and assign height to the node is max of the two children + 1. But ... Read More

Find coordinates of the triangle given midpoint of each side in C++

Arnab Chakraborty
Updated on 17-Dec-2019 10:19:20

105 Views

Suppose we have three coordinates which are midpoint of sides of the triangle. We have to find the coordinates of the triangle. So if the inputs are like (5, 3), (4, 4), (5, 5), then output will be (4, 2), (4, 6), (6, 4).To solve this, we have to solve for X-coordinates and Y-coordinates separately. For X coordinate of vertices, let them be x1, x2, x3. Then, X-coordinate of middle points will be (x1 + x2)/2, (x2 + x3)/2, (x3 + x1)/2. If we observe the sum of these three expressions is equal to sum of X-coordinates. Now, we have ... Read More

Find closest number in array in C++

Arnab Chakraborty
Updated on 17-Dec-2019 10:16:42

3K+ Views

Suppose we have an array A with n elements. And elements are sorted. We have to find the closest value to the given integer. The array may contain duplicate values and negative numbers. So if the array is like [2, 5, 6, 7, 8, 8, 9] and the target number is 4, then closest element is 5.We can solve this by traversing through the given array and keep track of absolute difference of current element with every element. Finally return the element that has minimum absolute difference.Example Live Demo#include #include using namespace std; int getNearest(int x, int y, int target) { ... Read More

C++ Program to implement t-test

Ayush Gupta
Updated on 03-Dec-2019 11:26:46

685 Views

In this tutorial, we will be discussing a program to implement t-test.The t-test of the student’s T test is used to compare two means and tell if both of them are similar or different. Along with this, t-test also helps to determine how large the differences are to know the reason for the change.Example#include using namespace std; //calculating mean float calc_mean(float arr[], int n){    float sum = 0;    for (int i = 0; i < n; i++)       sum = sum + arr[i];    return sum / n; } //calculating standard deviation float calc_deviation(float arr[], ... Read More

C++ Program to implement standard error of mean

Ayush Gupta
Updated on 03-Dec-2019 11:25:42

222 Views

In this tutorial, we will be discussing a program to implement standard error of mean.Standard error of mean is the estimation of sample mean dispersion from population mean. Then it is used to estimate the approximate confidence intervals for the mean.Example#include using namespace std; //calculating sample mean float calc_mean(float arr[], int n){    float sum = 0;    for (int i = 0; i < n; i++)       sum = sum + arr[i];    return sum / n; } //calculating standard deviation float calc_deviation(float arr[], int n){    float sum = 0;    for (int i = ... Read More

C++ program to implement Run Length Encoding using Linked Lists

Ayush Gupta
Updated on 10-Jul-2020 05:52:47

225 Views

In this tutorial, we will be discussing a program to implement Run Length Encoding using Linked Lists.For this we will be given with a linked list. OUr task is too encode the elements of the Linked List using Run Length Encoding.For example, if the elements of the linked list are “a->a->a->a->a” then in run length encoding they will be replaced by “a → 5”.Example#include using namespace std; //structuring linked list node struct Node {    char data;    struct Node* next; }; //creating a new node Node* newNode(char data){    Node* temp = new Node;    temp->data = data; ... Read More

C++ program to implement standard deviation of grouped data

Ayush Gupta
Updated on 03-Dec-2019 10:36:51

270 Views

In this tutorial, we will be discussing a program to implement standard deviation of grouped data.For this we will be given with class interval and frequency of the class. Our task is to find the standard deviation of the grouped data.Example#include using namespace std; //finding mean of grouped data float calc_mean(float mid[], int freq[], int n){    float sum = 0, freqSum = 0;    for (int i = 0; i < n; i++) {       sum = sum + mid[i] * freq[i];       freqSum = freqSum + freq[i];    }    return sum / ... Read More

C++ program to implement Simpson’s 3/8 rule

Ayush Gupta
Updated on 03-Dec-2019 10:34:00

838 Views

In this tutorial, we will be discussing a program to implement SImpson’s ⅜ rule.Simpson’s ⅜ rule is used for doing numerical integrations. The most common use case of this method is in performing numerical approximations of definite integrals.In this, the parabolas on the graph are used for performing the approximations.Example#include using namespace std; //function that is to be integrated float func_inte( float x){    return (1 / ( 1 + x * x )); } //calculating the approximations float func_calculate(float lower_limit, float upper_limit, int interval_limit ){    float value;    float interval_size = (upper_limit - lower_limit) / interval_limit;    float ... Read More

Advertisements