Ayush Gupta

Ayush Gupta

433 Articles Published

Articles by Ayush Gupta

Page 41 of 44

Count all pairs of an array which differ in K bits in C++

Ayush Gupta
Ayush Gupta
Updated on 10-Feb-2020 225 Views

In this tutorial, we will be discussing a program to find the number of pairs of an array which differ in K bits.For this we will be provided with an array and an integer K. Our task is to find the number of pairs who differ by K bits in their binary representation.Example#include using namespace std; //counting number of bits in //binary representation int count_bit(int n){    int count = 0;    while (n) {       if (n & 1)          ++count;       n >>= 1;    }    return count; } ...

Read More

Converting one string to other using append and delete last operations in C++

Ayush Gupta
Ayush Gupta
Updated on 29-Jan-2020 164 Views

In this tutorial, we will be discussing a program to convert one string to other using append and delete last operations.For this we will be provided with two strings. Our task is to calculate whether the first string can be converted into the second one by performing k operations of append and delete last element.Example#include using namespace std; //checking if conversion between strings is possible bool if_convert(string str1, string str2, int k){    if ((str1.length() + str2.length()) < k)    return true;    //finding common length of both string    int commonLength = 0;    for (int i = ...

Read More

Convert given time into words in C++

Ayush Gupta
Ayush Gupta
Updated on 22-Jan-2020 369 Views

In this tutorial, we will be discussing a program to convert given time into words. For this we will be provided with a specific time in the digital format.Our task is to convert that particular time into wordsExample#include using namespace std; //printing time in words void convert_time(int h, int m){    char nums[][64] = {       "zero", "one", "two", "three", "four",       "five", "six", "seven", "eight",       "nine", "ten", "eleven", "twelve",       "thirteen", "fourteen", "fifteen",       "sixteen", "seventeen", "eighteen",       "nineteen", "twenty", "twenty       one", ...

Read More

Program to print last N lines in c++

Ayush Gupta
Ayush Gupta
Updated on 02-Jan-2020 476 Views

In this tutorial, we will be discussing a program to print the last N lines.For this, we will be provided with a string that consists of the new line character to denote the start of the next line and the number of lines to be printed from the last. Our task is to start from the last and print all the N lines counting from the last.Example#include using namespace std; #define DELIM '' //printing the last N lines void print_last_lines(char *str, int n){    if (n

Read More

C++ Program to implement t-test

Ayush Gupta
Ayush Gupta
Updated on 03-Dec-2019 1K+ 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
Ayush Gupta
Updated on 03-Dec-2019 314 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 Simpson's 3/8 rule

Ayush Gupta
Ayush Gupta
Updated on 03-Dec-2019 1K+ 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

C++ Program to implement Linear Extrapolation

Ayush Gupta
Ayush Gupta
Updated on 03-Dec-2019 997 Views

In this tutorial, we will be discussing a program to implement Linear Extrapolation.Extrapolation is defined as a process in which the required value for a certain function is beyond the lower or the upper limits of the function definition.In the case of Linear Extrapolation, the value beyond the scope is found using the tangent made on the graph of the function to determine the required value. Linear Extrapolation gives quite accurate results when applied.Example#include using namespace std; //structuring the values of x and y struct Data {    double x, y; }; //calculating the linear extrapolation double calc_extrapolate(Data d[], ...

Read More

C++ program to implement Inverse Interpolation using Lagrange Formula

Ayush Gupta
Ayush Gupta
Updated on 03-Dec-2019 493 Views

In this tutorial, we will be discussing a program to implement Inverse Interpolation using Lagrange formula.Inverse Interpolation is defined as the method of finding the value of an independent variable from the given value of dependent value lying between two tabulated set of values for an unknown function.Example#include using namespace std; //structuring the values of x and y struct Data {    double x, y; }; //calculating inverse interpolation double calc_invinter(Data d[], int n, double y){    double x = 0;    int i, j;    for (i = 0; i < n; i++) {       double ...

Read More

C++ program to implement Collatz Conjecture

Ayush Gupta
Ayush Gupta
Updated on 03-Dec-2019 508 Views

In this tutorial, we will be discussing a program to implement Collatz Conjecture.For this, we will be given with a number n and we have to find out whether it can be converted to 1 using two operations −If n is even, n is converted to n/2.If n is odd, n is converted to 3*n + 1.Example#include using namespace std; //checking if n reaches to 1 or not bool check1(int n, unordered_set &s){    if (n == 1)       return true;    if (s.find(n) != s.end())       return false;    return (n % 2)? check1(3*n + ...

Read More
Showing 401–410 of 433 articles
Advertisements