Ayush Gupta

Ayush Gupta

433 Articles Published

Articles by Ayush Gupta

Page 27 of 44

Program to find minimum number of lectures to attend to maintain 75% in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 1K+ Views

In this problem, we are given two numbers M and N that denote the total number of classes held till present data and the number of classes attended by the student respectively. Our task is to create a program to find minimum number of lectures to attend to maintain 75% in C++.Problem DescriptionThis is one of the biggest concerns of college students to maintain 75% percent attendance. This program calculates the minimum number of lectures that are to be attended regularly by the student to get an attendance of 75%.Let’s take an example to understand the problem, Example 1Input: M ...

Read More

Program to find N-th term of series a, b, b, c, c, c...in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 384 Views

In this problem, we are given a number N. Our task is to create a Program to find N-th term of series a, b, b, c, c, c…in C++.Problem DescriptionTo find the Nth term of the series −a, b, b, c, c, c, d, d, d, d, ....Nterms We need to find the general term of the series.Let’s take an example to understand the problem, InputN = 7OutputdSolution ApproachTo find the general term of the series, we need to closely observe the series. The series has 1 a, 2 b’s, 3 c’s, 4 d’s, ... This seems to be an AP. ...

Read More

Program to find N-th term in the given series in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 318 Views

In this problem, we are given a number N. Our task is to create a program to find N-th term in the given series in C++.Problem DescriptionTo find the sum of the given series −1, 1, 2, 3, 4, 9, 8, 27, 16, 81, 32, 243, 64, 729, 128, 2187, 256, ... NTermsWe will find the general term of the series.Let’s take an example to understand the problem, Example 1InputN = 6Output9Example 2InputN = 13Output64Solution ApproachTo solve the problem, we need to carefully observe the series. As it is, a mixture series and these types of series are difficult to ...

Read More

Program to find Nth term divisible by a or b in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 775 Views

In this problem, we are given three numbers A, B, and N. Our task is to create a program to find Nth term divisible by A or B in C++.Problem DescriptionThe Nth Term divisible by A or B. Here, we will find the term n number term which is divisible by number A or B. For this, we will count till nth numbers that are divisible by A or B.Let’s take an example to understand the problem, InputA = 4, B = 3, N = 5Output9ExplanationThe terms the are divisible by 3 and 4 are −3, 4, 6, 8, 9, ...

Read More

How to find common elements between two Arrays using STL in C++?

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 315 Views

In this tutorial, we will be discussing a program to understand how to find common elements between two arrays using STL in C++.To find the common elements between two given arrays we will be using the set_intersetion() method.Example#include using namespace std; int main(){    //defining the array    int arr1[] = { 1, 45, 54, 71, 76, 12 };    int arr2[] = { 1, 7, 5, 4, 6, 12 };    int n1 = sizeof(arr1) / sizeof(arr1[0]);    int n2 = sizeof(arr2) / sizeof(arr2[0]);    sort(arr1, arr1 + n1);    sort(arr2, arr2 + n2);    cout

Read More

Insertion sort using C++ STL

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 861 Views

In this tutorial, we will be discussing a program to understand the insertion sort using C++ STL.In this we use std::upper_bound to find the element at the wrong position, then rotate the unsorted part of the array to make it sorted.Example#include //function to perform insertion sort void insertionSort(std::vector &vec){    for (auto it = vec.begin(); it != vec.end(); it++){       auto const insertion_point =       std::upper_bound(vec.begin(), it, *it);       std::rotate(insertion_point, it, it+1);    } } //printing the array void print(std::vector vec){    for( int x : vec)    std::cout

Read More

Program to find N-th term of series 0, 0, 2, 1, 4, 2, 6, 3, 8...in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 267 Views

In this problem, we are given a number N. Our task is to create a program to find N-th term of series 0, 0, 2, 1, 4, 2, 6, 3, 8…in C++.Problem descriptionTo find the Nth term of the given series−0, 0, 2, 1, 4, 2, 6, 3, 8 .... N TermsWe will find the general term of the series.Let’s take an example to understand the problem, InputN = 8Output3Solution ApproachTo find the general term of the series, we need to closely observe the series. This series is a bit difficult to recognize as it is a mixture of two ...

Read More

Program to find N-th term of series 0, 7, 8, 33, 51, 75, 102, 133...in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 155 Views

In this tutorial, we will be discussing a program to find N-th term of series 0, 7, 8, 33, 51, 75, 102, 133...For this, we will be provided with a number. Our task is to find the term for the given series at that particular position.Example#include #include using namespace std; //calculating nth term of series int nthTerm(int n) {    return 2 * pow(n, 2) + n - 3; } int main() {    int N = 4;    cout

Read More

How to find the sum of elements of a Vector using STL in C++?

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 912 Views

In this tutorial, we will be discussing a program to understand how to find the sum of elements of a vector using STL in C++.To find the sum of elements of a given vector, we would be using the accumulate() method from the STL library.Example#include using namespace std; int main(){    //defining the vector    vector a = { 1, 45, 54, 71, 76, 12 };    cout

Read More

Internal details of std::sort() in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 302 Views

In this tutorial, we will be discussing a program to understand the internal details of std::sort() in C++.std::sort() function is used to sort down an array using a comparison of the elements. If we look at the in-depth functionality of std::sort() it uses IntroSort algorithm to sort the elements of a container object.Example#include using namespace std; int main(){    int arr[] = {1, 5, 8, 9, 6, 7, 3, 4, 2, 0};    int n = sizeof(arr)/sizeof(arr[0]);    sort(arr, arr+n);    cout

Read More
Showing 261–270 of 433 articles
« Prev 1 25 26 27 28 29 44 Next »
Advertisements