Sunidhi Bansal

Sunidhi Bansal

809 Articles Published

Articles by Sunidhi Bansal

Page 4 of 81

Product of middle row and column in an odd square matrix in C

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 317 Views

Given a square matrix, mat[row][column] where row and column are equal and are of odd length, the task is to find the product of middle row and middle column of that matrix. The matrix must have odd dimensions so there's always a clear middle row and column. 1 2 3 4 5 ...

Read More

Program to compare two fractions in C

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 800 Views

In C programming, comparing two fractions requires cross-multiplication to avoid floating-point precision issues. Given two fractions with numerators and denominators, we need to determine which fraction has the greater value. Syntax struct Fraction { int nume, deno; }; struct Fraction greater(struct Fraction first, struct Fraction second); Approach To compare fractions a/b and c/d, we use cross-multiplication: if a*d > b*c, then a/b > c/d. This avoids floating-point division and maintains precision. Example 1: Basic Fraction Comparison This example compares 4/5 and 3/4 using cross-multiplication − ...

Read More

Program to check if an array is sorted or not (Iterative and Recursive) in C

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 4K+ Views

Given an array arr[] with n number of elements, our task is to check whether the given array is in sorted order or not. If it is in sorted order then print "The array is in sorted order", else print "The array is not in sorted order". To solve this problem we can use iterative or recursive approach, we will be discussing both. Syntax int isSorted(int arr[], int n); Method 1: Iterative Approach In iterative approach, we use loops to traverse the array and compare adjacent elements ? #include ...

Read More

Program to check if a string contains any special character in C

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 7K+ Views

In C programming, checking if a string contains special characters is a common validation task. Special characters are those that are neither alphabetic nor numeric, such as symbols like !@#$%^&*() etc. Syntax int checkSpecialCharacter(char str[], int length); Method 1: Using Character Comparison This method iterates through each character and compares it against a predefined set of special characters − #include #include int checkSpecialCharacter(char str[], int n) { int i; for (i = 0; i < n; i++) { ...

Read More

Product of N with its largest odd digit in C

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 494 Views

In C programming, we need to find the product of a given number N with its largest odd digit. If the number contains no odd digits, we return -1. Syntax int largestOddDigit(int n); int findProduct(int n); Algorithm Extract each digit of the number using modulo operation Check if the digit is odd and compare with the current largest odd digit Keep track of the maximum odd digit found Multiply the original number with the largest odd digit Return -1 if no odd digit exists Example 1: Number with Odd Digits ...

Read More

Product of maximum in first array and minimum in second in C

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 390 Views

Given two arrays, we need to find the product of the maximum element from the first array and the minimum element from the second array. This is a common programming problem that demonstrates array traversal and basic mathematical operations. Syntax int findMaxElement(int arr[], int size); int findMinElement(int arr[], int size); int calculateProduct(int arr1[], int arr2[], int n1, int n2); Method 1: Using Sorting Approach In this approach, we sort both arrays and then multiply the last element of the first array with the first element of the second array − #include ...

Read More

Maximum number of threads that can be created within a process in C

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 1K+ Views

In this article, we will explore how to determine the maximum number of threads that can be created within a process in C. Understanding thread limits is crucial for developing efficient multi-threaded applications. A thread is a lightweight process that can be independently managed by the scheduler. Multiple threads can be associated with a single process, and they require less time for context switching compared to processes. Threads share memory with their peer threads and require fewer resources for creation and termination. Syntax int pthread_create(pthread_t *thread, const pthread_attr_t *attr, ...

Read More

Count minimum bits to flip such that XOR of A and B equal to C in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 464 Views

We are given three binary sequences A, B and C of length N. Each sequence represents a binary number. We have to find the number of bit flips required in A and B such that XOR of A and B results in C. Syntax int flipCount(int A[], int B[], int C[], int n); First, let us understand the XOR operation truth table − X ...

Read More

mbrtowc() function in C/C++ program

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 314 Views

The mbrtowc() function is used to convert a multibyte character sequence to a wide character. This function is part of the C standard library and is defined in the header file. It provides a safe way to convert multibyte characters (like UTF-8) to wide character representation. Syntax size_t mbrtowc(wchar_t* pwc, const char* s, size_t n, mbstate_t* ps); Parameters The function accepts the following parameters − pwc − Pointer to the location where the resulting wide character will be stored s − Pointer to the multibyte character string to be converted n ...

Read More

putwchar() function in C/C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 173 Views

The putwchar() function in C is used to write a wide character to the standard output (stdout). It is the wide character equivalent of the putchar() function and is defined in the header file. Syntax wint_t putwchar(wchar_t wc); Parameters wc − The wide character to be written to stdout Return Value On success: Returns the wide character that was written On failure: Returns WEOF and sets an error indicator Example 1: Writing Single Wide Character This example demonstrates writing a single wide character to stdout ...

Read More
Showing 31–40 of 809 articles
« Prev 1 2 3 4 5 6 81 Next »
Advertisements