Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Server Side Programming Articles
Page 902 of 2109
C Program to Find Minimum Insertions to Form a Palindrome
A palindrome is a string that reads the same forwards and backwards. Given a string, we need to find the minimum number of character insertions required to make it a palindrome. We will explore three approaches − recursive, memoization, and dynamic programming. Syntax int minInsertions(char str[], int start, int end); Method 1: Recursive Approach The recursive approach compares characters from both ends. If they match, we move inward; otherwise, we try inserting at either end and take the minimum ? #include #include #include int findMin(int a, int b) ...
Read MoreLocate unused structures and structure-members
Structures in C are user-defined data types that group related variables together. As codebases grow, some structures and their members may become unused, leading to cluttered code and wasted memory. This article explores methods to identify and remove unused structures and structure members in C programs. Syntax struct structure_name { data_type member1; data_type member2; // ... more members }; Why Remove Unused Structures and Members? Unused structures and members can impact performance and readability of your code. Here are some reasons why ...
Read MoreCorrupt stack problem in C, C++ program
The corrupt stack problem is a critical runtime issue in C programming that occurs when the program's stack memory becomes compromised. This can lead to unpredictable program behavior, crashes, and security vulnerabilities. Understanding stack corruption is essential for writing robust C programs. What is a Stack in C? In C, the stack is a region of memory used for automatic storage of local variables, function parameters, and return addresses. It operates on a Last-In-First-Out (LIFO) principle, where the most recently allocated memory is freed first when functions return. What is Corrupt Stack Problem? Stack corruption occurs ...
Read MoreC program to implement CHECKSUM
In computing, a checksum is a small-sized data value computed from a larger data set using an algorithm, with the intention that any changes made to the larger data set will result in a different checksum. Checksums are commonly used to verify the integrity of data during transmission or storage. Syntax unsigned int checksum(char *data); // Returns computed checksum value for given data Why Use CHECKSUM? There are several reasons why checksums are used − Error detection − Detect errors that occur during data transmission or storage Data integrity − Ensure data ...
Read Morefopen() for existing file in write mode in C
The fopen() function in C is used to open files for various operations. When opening an existing file in write mode, it's important to understand how different modes affect the file's content. Syntax FILE *fopen(const char *filename, const char *mode); fopen() for an Existing File in Write Mode When using fopen() with write mode on an existing file − 'w' mode: Creates a new file if it doesn't exist, or truncates (empties) an existing file before writing 'w+' mode: Same as 'w' but allows both reading and writing 'a' mode: Appends new ...
Read MoreC Program to Redeclaration of global variable
In C programming, variable redeclaration refers to declaring a variable more than once in the same scope. The behavior of redeclaration varies between global and local variables, and differs between C and C++. Understanding these differences is crucial for avoiding compilation errors. Syntax // Global variable redeclaration int var; int var; // Allowed in C without initialization // Local variable redeclaration int main() { int var; int var; // Not allowed in C } Global Variable Redeclaration Without Initialization C allows ...
Read MoreC program to demonstrate usage of variable-length arrays
Variable-length arrays (VLAs) in C allow you to create arrays whose size is determined at runtime rather than compile time. This feature was introduced in C99 and provides dynamic array allocation on the stack. In this example, we'll demonstrate a library system that uses VLAs to manage books on shelves with three operations: adding books, querying book pages, and counting books per shelf. Syntax data_type array_name[variable_size]; // Where variable_size is determined at runtime Library Management System The system supports three commands − Command 1: Insert a book with y pages at shelf ...
Read MoreC program to find out the maximum value of AND, OR, and XOR operations that are less than a given value
Suppose we are given two integers k and n. Our task is to perform three operations; bitwise AND, bitwise OR, and bitwise XOR between all pairs of numbers up to range n. We return the maximum value of all three operations between any two pairs of numbers that is less than the given value k. So, if the input is like n = 5, k = 5, then the output will be 4 3 4. The greatest value of AND, OR, and XOR operations between all pairs of numbers that are less than 5 are 4, 3, and ...
Read MoreC program to sort triangles based on area
Suppose we have an array of different triangles where triangles[i] = [ai, bi, ci] these are the sides of ith triangle. We shall have to sort the triangles based on their area. The area of a triangle using sides is calculated with Heron's formula: square root of p*(p-a)*(p-b)*(p-c) where p = (a+b+c)/2. So, if the input is like (7, 24, 25), (5, 12, 13), (3, 4, 5), then the output will be (3, 4, 5), (5, 12, 13), (7, 24, 25) Syntax struct Triangle { int a, b, c; }; int ...
Read MoreC program to find sum, max and min with Variadic functions
Variadic functions in C allow you to create functions that can accept a variable number of arguments. This is useful when you need functions like sum(), max(), and min() that can work with different numbers of input values. To implement variadic functions, we use the ellipsis (...) notation and include the header file. Syntax return_type function_name(fixed_parameter, ...); The key macros for handling variable arguments are − va_list: Stores information about variable arguments va_start: Initializes the va_list to start accessing arguments va_arg: Retrieves the next argument of specified type va_end: Cleans up the ...
Read More