Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 15 of 377

Alphanumeric Abbreviations of a String in C Program?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 619 Views

In C programming, generating alphanumeric abbreviations of a string means creating all possible combinations where some characters can be replaced with numbers representing the count of omitted characters. For example, "HELLO" can be abbreviated as "HE2O" where "2" represents the two omitted characters "LL". Syntax void printAbbreviation(const char* s, int index, int max_index, char* str, int str_len); Algorithm The recursive algorithm works as follows − printAbbreviation(s, index, max, str) − begin if index is same as max, then print str ...

Read More

Addition and Subtraction of Matrix using pthreads in C/C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 1K+ Views

Matrix addition and subtraction using pthreads allows us to perform operations on large matrices efficiently by utilizing multiple threads. Each thread handles a portion of the matrix, enabling parallel computation and improved performance. To compile and run pthread programs, you need to link with the pthread library using: gcc -pthread program.c -o program Syntax pthread_create(&thread_id, NULL, function_name, (void*)argument); pthread_join(thread_id, NULL); Example: Matrix Operations with Pthreads This example demonstrates matrix addition and subtraction using multiple threads. Each thread processes one row of the matrices − #include #include #include ...

Read More

C/C++ Program to Find sum of Series with n-th term as n power of 2 - (n-1) power of 2

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 215 Views

Here we will see how to get the sum of the series with n-th term as n2 − (n−1)2. The recurrence relation is like below − Tn = n2 − (n−1)2 So the series is − S = T₁ + T₂ + T₃ + ... + Tₙ S = (1² - 0²) + (2² - 1²) + (3² - 2²) + ... + (n² - (n-1)²) S = 1 + 3 + 5 + ... + (2n-1) = n² We need to find S mod (109 + 7), ...

Read More

Types of Polymorphisms - Ad-hoc, Inclusion, Parametric & Coercion

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 4K+ Views

Polymorphism is a fundamental concept in programming that allows entities to take multiple forms. There are four main types of polymorphism − Ad-Hoc Polymorphism (Function Overloading) Inclusion Polymorphism (Subtyping) Parametric Polymorphism (Generics/Templates) Coercion Polymorphism (Type Casting) Note: This article explains polymorphism concepts using C syntax for illustration. Pure C doesn't support object-oriented polymorphism natively, but these concepts can be demonstrated through function pointers and other techniques. Ad-Hoc Polymorphism (Function Overloading) Ad-hoc polymorphism allows multiple functions with the same name to operate on different data types. In C, this is achieved through different ...

Read More

A Puzzle using C Program

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 764 Views

Here we will see one C puzzle question. Suppose we have two numbers 48 and 96. We have to add the first number after the second one. So final result will be like 9648. But we cannot use any logical, arithmetic, string related operations, also cannot use any pre-defined functions. So how can we do that? This is easy. We can do by using Token Pasting operator (##) in C. The Token Pasting operator is a preprocessor operator. It sends commands to compiler to add or concatenate two tokens into one string. We use this operator at the macro ...

Read More

3-Way QuickSort (Dutch National Flag)

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 2K+ Views

The 3-Way QuickSort, also known as the Dutch National Flag algorithm, is an optimized version of the standard QuickSort algorithm. While traditional QuickSort partitions the array into two parts (less than and greater than pivot), 3-Way QuickSort creates three partitions: elements less than pivot, equal to pivot, and greater than pivot. Syntax void partition(int arr[], int left, int right, int *i, int *j); void quicksort3Way(int arr[], int left, int right); Algorithm The partition function divides the array into three sections − partition(arr, left, right, i, j): if right - left

Read More

A Space Optimized Solution of LCS in C Program?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 282 Views

Here we will see one space optimized approach for LCS problem. The LCS is the longest common subsequence. If two strings are "BHHUBC" and "HYUYBZC", then the length of the subsequence is 4. One dynamic programming approach is already there, but using the dynamic programming approach, it will take more space. We need table of order m x n, where m is the number of characters in first string, and n is the number of characters in the second string. Here we will see how to implement this algorithm using O(n) amount of auxiliary space. If we observe the ...

Read More

A Peterson Graph Problem in C Program?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 376 Views

The Peterson Graph is a specific undirected graph with 10 vertices and 15 edges. In this problem, we need to find a walk through the Peterson Graph that realizes a given string pattern. Each vertex is labeled with a letter (A-E), and we must find a path where the sequence of vertex labels matches our target string. ...

Read More

A C/C++ Pointer Puzzle?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 460 Views

This C programming puzzle demonstrates how pointer arithmetic works with different types of pointers and multi-dimensional arrays. Understanding pointer sizes and type differences is crucial for mastering pointer arithmetic in C. Syntax sizeof(pointer_variable) (char*)(pointer + 1) - (char*)pointer Example: Pointer Arithmetic Puzzle Let's analyze this step-by-step with a complete C program that demonstrates pointer arithmetic with various pointer types − #include int main() { int a[4][5][6]; int x = 0; int* a1 = &x; ...

Read More

3-digit Osiris number C Program?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 227 Views

An Osiris number is a special 3-digit number that equals the sum of all permutations of its 2-digit sub-samples. For example, 132 is an Osiris number because 12 + 21 + 13 + 31 + 23 + 32 = 132. Syntax bool isOsirisNumber(int n); Algorithm The approach is straightforward. For a 3-digit number, each digit appears exactly twice in the permutations − once in the tens position and once in the ones position. Therefore, we can check if the number equals 22 times the sum of its digits. Begin ...

Read More
Showing 141–150 of 3,768 articles
« Prev 1 13 14 15 16 17 377 Next »
Advertisements