Server Side Programming Articles

Page 1345 of 2109

Count all the numbers in a range with smallest factor as K in C++

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

In this tutorial, we will be discussing a program to find the numbers in a range with the smallest factor as K.For this we will be provided with a range [a,b]. Our task is to count the numbers in the given range who have their smallest factor as K.Example#include using namespace std; //checking if K is a prime bool if_prime(int k){    if (k

Read More

Handling the Divide by Zero Exception in C++

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

In this tutorial, we will be discussing how to handle the divide by Zero exception in C++.Division by zero is an undefined entity in mathematics, and we need to handle it properly while programming so that it doesn’t return at error at the user end.Using the runtime_error classExample#include #include using namespace std; //handling divide by zero float Division(float num, float den){    if (den == 0) {       throw runtime_error("Math error: Attempted to divide by Zero");    }    return (num / den); } int main(){    float numerator, denominator, result;    numerator = 12.5;    denominator = 0;    try {       result = Division(numerator, denominator);       cout

Read More

Count all the columns in a matrix which are sorted in descending in C++

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

In this tutorial, we will be discussing a program to find the number of columns in a matrix which are sorted in descending.For this we will be provided with a matrix. Our task is to count the number of columns in the matrix having elements sorted in descending order.Example#include #define MAX 100 using namespace std; //counting columns sorted in descending order int count_dcolumns(int mat[][MAX], int r, int c){    int result = 0;    for (int i=0; i0; j--)          if (mat[i][j-1] >= mat[i][j])             break;       if (c ...

Read More

Count all sorted rows in a matrix in C++

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

In this tutorial, we will be discussing a program to find the number of all sorted rows in a matrix.For this we will be provided with m*n matrix. Our task is to count all the rows in the given matrix that are sorted either in ascending or descending order.Example#include #define MAX 100 using namespace std; //counting sorted rows int count_srows(int mat[][MAX], int r, int c){    int result = 0;    for (int i=0; i

Read More

Count all sub-arrays having sum divisible by k

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

In this tutorial, we will be discussing a program to find the number of sub-arrays having sum divisible by k.For this we will be provided with an array and a value k. Our task is to find the number of sub arrays that are having their sum as equal to the given value k.Example#include using namespace std; //counting subarrays with k sum int count_subarray(int arr[], int n, int k){    int mod[k];    memset(mod, 0, sizeof(mod));    int cumSum = 0;    for (int i = 0; i < n; i++) {       cumSum += arr[i];   ...

Read More

Count all Quadruples from four arrays such that their XOR equals to 'x' in C++

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

In this tutorial, we will be discussing a program to find the number of quadruples from four arrays such that their XOR equals to x.For this we will be provided with four arrays and a value x. Our task is to count all the quadruples whose XOR is equal to the given value x.Example#include using namespace std; //counting quadruples with XOR equal to x int count_quad(int a[], int b[], int c[], int d[], int x, int n){    int count = 0;    for (int i = 0 ; i < n ; i++)       for (int j ...

Read More

Count all prefixes of the given binary array which are divisible by x in C++

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

In this tutorial, we will be discussing a program to find the number of prefixes of the binary array which are divisible by x.For this we will be provided with binary array and a value x. Our task is to find the number of elements whose prefixes are divisible by given value x.Example#include using namespace std; //counting the elements with prefixes //divisible by x int count_divx(int arr[], int n, int x){    int number = 0;    int count = 0;    for (int i = 0; i < n; i++) {       number = number * ...

Read More

Count all possible walks from a source to a destination with exactly k edges in C++

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

In this tutorial, we will be discussing a program to find the number of walks from a source to a destination with exactly k edges.For this we will be provided with a graph and the values of source and destination. Our task is to find all the possible paths starting from the source to the destination having exactly k edges.Example#include using namespace std; #define V 4 //counting walks using recursion int countwalks(int graph[][V], int u, int v, int k){    if (k == 0 && u == v)       return 1;    if (k == 1 && graph[u][v])       return 1;    if (k

Read More

How to create a List with Constructor in C++ STL

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

In this tutorial, we will be discussing a program to understand how to create a List with constructor in C++ STL.List are data structures to store elements in memory in a non-contiguous fashion. They are insertion and deletion quick as compared to vectors.Example#include #include using namespace std; //printing the list void print_list(list mylist){    list::iterator it;    //printing all the elements    for (it = mylist.begin(); it != mylist.end(); ++it)       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 940 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
Showing 13441–13450 of 21,090 articles
Advertisements