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
C Articles
Page 35 of 96
Count minimum bits to flip such that XOR of A and B equal to C in C++
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 MoreFind a permutation that causes worst case of Merge Sort in C
Merge sort has a consistent O(n log n) time complexity, but in practice, certain input permutations require more comparisons during the merge operations. The worst case occurs when the merge operation at each level compares every element from both subarrays before completing. Syntax void generateWorstCase(int arr[], int left, int right); Understanding the Worst Case The worst case for merge sort happens when at each merge operation, elements from left and right subarrays are alternately selected. This forces maximum comparisons since we cannot skip any elements during merging. Algorithm To generate the worst ...
Read Morefillpoly() function in C
The fillpoly() function in C is part of the graphics.h library and is used to draw and fill a polygon with the current fill pattern and color. It takes the same arguments as drawpoly() but additionally fills the interior of the polygon. Syntax void fillpoly(int numpoints, int *polypoints); Parameters numpoints − Specifies the number of points in the polygon polypoints − Pointer to an array containing x, y coordinates of each point The polypoints array should contain numpoints * 2 integers, where each pair represents the x and y coordinates of ...
Read MoreFlood fill algorithm using C graphics
The flood fill algorithm is a technique used to fill a connected region with a specific color. It starts from a seed pixel and recursively fills all adjacent pixels that have the same color as the original pixel. Syntax void floodFill(int x, int y, int newColor, int oldColor); Note: This example requires Turbo C/C++ or a compatible graphics library with graphics.h support. Modern compilers may need additional setup for graphics functions. Algorithm Steps The flood fill algorithm follows these steps − Check if the current pixel coordinates are within ...
Read MoreC program to simulate Nondeterministic Finite Automata (NFA)
In this problem, we will create a C program to simulate Non-deterministic Finite Automata (NFA). NFA is a finite state machine that can move to any combination of states for an input symbol, meaning there is no exact state to which the machine will move. Syntax struct node { int data; struct node* next; char edgetype; }; int nfa(node** graph, int current, char* input, int* accept, int start); Formal Definition of NFA NFA can be represented by 5-tuple (Q, Σ, δ, ...
Read MoreC Program to reverse each node value in Singly Linked List
In this article, we are given a singly linked list. Our task is to create a C program to reverse each node value in the linked list − meaning if a node contains 123, it should become 321. A singly linked list is a linear data structure where each node contains data and a pointer to the next node in the sequence. Problem Example Input: 34 → 12 → 89 → 56 → 72 Output: 43 → 21 → 98 → 65 → 27 Approach To solve this problem, we will: Traverse each ...
Read MoreC program to Replace a word in a text by another given word
In this program, we have given three strings: text, oldword, and newword. Our task is to create a C program to replace a word in a text by another given word. The program will search for all the occurrences of the oldword in the text and replace it with newword. Syntax void replaceWordInText(const char *text, const char *oldWord, const char *newWord); Example: Input and Expected Output Let's take an example to understand the problem − Input: text = "I am learning programming" oldword = "learning" newword = "practicing" Output: ...
Read MoreC program to print number series without using any loop
In this problem, we are given two numbers N and K. Our task is to create a program that will print number series without using any loop. The series starts from N and subtracts K until it becomes zero or negative. After that, we start adding K to it until it becomes N again. We cannot use any type of loop for this process. Syntax void printSeries(int current, int n, int k, int flag); Input/Output Example Input: n = 12, k = 3 Output: 12 9 6 3 0 3 6 9 ...
Read MoreC program to print environment variables
In C programming, environment variables are global system variables that contain information about the operating system and user environment. These variables can affect how running processes behave on the system. C provides access to environment variables through the third parameter of the main() function. Syntax int main(int argc, char *argv[], char *envp[]) Parameters: argc − Number of command-line arguments argv[] − Array of command-line argument strings envp[] − Array of environment variable strings (NULL-terminated) Example: Print All Environment Variables This program iterates through the envp array to print all environment variables ...
Read MoreC Program to list all files and sub-directories in a directory
In C, we can list all files and sub-directories in a directory using the dirent.h header which provides directory handling functions. This is useful for file system operations and directory traversal programs. A directory is a container that stores files and other directories in a hierarchical structure. A subdirectory is a directory contained within another directory, creating nested folder structures. Note: This program requires a POSIX-compliant system (Linux/Unix/macOS). On Windows, you may need to use different headers or compile with specific flags. Syntax DIR *opendir(const char *dirname); struct dirent *readdir(DIR *dirp); int closedir(DIR ...
Read More