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 2 of 96
Position of the leftmost set bit in a given binary string where all 1s appear at the end
The aim of this article is to implement a program to find the position of the leftmost set bit in a given binary string where all 1s appear at the end. A binary string is a sequence of bits (0s and 1s) used to represent data in binary format. In this problem, we are given a binary string where all the 1s are grouped together at the rightmost positions, and we need to find the leftmost position where the first '1' appears. Syntax int findFirstBit(char* str, int length); Problem Statement Given a binary ...
Read Morelargest string formed by choosing words from a given Sentence as per given Pattern
To find the largest string formed by choosing words from a given sentence, a user should know about the lexicographically largest string. A lexicographically largest string is a string, when sorted alphabetically, it would appear at the last if we form all possible strings from the selected words. For example: {lion, zebra, apple} will be lexicographically sorted as {apple, lion, zebra}. In this article, we have been given a string and a pattern. Based on this pattern, we have to find the lexicographically largest string matching the given pattern by choosing words from the sentence using C. Here is ...
Read MoreFind the count of Alphabetic and Alphanumeric strings from given Array of Strings
In C programming, counting alphabetic and alphanumeric strings from an array involves checking each character in every string. An alphabetic string contains only letters (a-z, A-Z), while an alphanumeric string contains both letters and digits (0-9). Syntax int isAlphabetic(char str[]); int isAlphanumeric(char str[]); void countStrings(char arr[][MAX_LEN], int n); Algorithm The approach to solve this problem involves the following steps − Step 1 − Iterate through each string in the array Step 2 − Check each character to determine if string is alphabetic or alphanumeric Step 3 − Count occurrences and maintain frequency ...
Read MoreCount of sum of “10” subsequences for each 1 in string with A 1s, B 10s and C 0s
In C programming, we need to find the count of "10" subsequences for each '1' in a string that contains A individual 1s, B "10" substrings, and C individual 0s. This problem involves counting subsequences where each '1' can pair with available '0' characters. Syntax long long maximumSubSeq(int A, int B, int C); Problem Understanding Given three parameters − A − Number of standalone '1' characters B − Number of "10" substrings C − Number of standalone '0' characters We need to count all possible "10" subsequences from the concatenated string. ...
Read MoreConvert a string Str1 to Str2 by moving B to right and A to left without crossover
The aim of this article is to implement a program to convert a string Str1 to Str2 by moving B to right and A to left without crossover. In this problem, we have two strings where characters 'A' can only move left, characters 'B' can only move right, and empty spaces are represented by '#'. The key constraint is that 'A' and 'B' characters cannot cross over each other during movement. Syntax bool moveRobots(char str1[], char str2[]); Examples Example 1 Input: str1 = "#B#A#", str2 = "##BA#" Output: Yes ...
Read MoreC Program To Write Your Own atoi()
The atoi() function in C converts a string representation of a number into an integer value. The name stands for "ASCII to Integer". While the standard library provides atoi(), implementing your own version helps understand string parsing and character-to-number conversion. Syntax int myAtoi(const char *str); Parameters str − Pointer to the null-terminated string to be converted Return Value Returns the converted integer value. If no valid conversion can be performed, it returns 0. Example 1: Basic Implementation This example shows a simple implementation that handles positive numbers − ...
Read MoreProducer-Consumer Problem in C
The producer-consumer problem is a classic synchronization challenge in concurrent programming where multiple threads share a common buffer. Producers generate data and place it into the buffer, while consumers remove and process data from the buffer. The main challenge is coordinating these operations to prevent race conditions and ensure data integrity. Syntax /* Basic structure for producer-consumer implementation */ pthread_t producer_thread, consumer_thread; pthread_mutex_t mutex; pthread_cond_t condition_variable; void* producer(void* arg); void* consumer(void* arg); Problem Statement The producer-consumer problem involves two types of processes − Producer − Generates data and puts it into ...
Read MoreNamed Pipe or FIFO with example C program
Named pipes, also referred to as FIFOs (First In, First Out), are essential IPC (Interprocess Communication) mechanisms in Unix-like systems. They provide a method for communication between unrelated processes running on the same system. Unlike anonymous pipes, named pipes exist as special files in the filesystem and can be accessed by any process with appropriate permissions. Named pipes follow the FIFO principle, ensuring that data written by one process is read by another process in the same order. This makes them particularly useful for producer-consumer scenarios and process synchronization. Syntax int mkfifo(const char *pathname, mode_t mode); ...
Read MoreC 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 MoreThe Ultimate Guide to Mastering Ping in C Programming: Basics, Commands, and Troubleshooting
In C programming, implementing a ping utility involves creating ICMP (Internet Control Message Protocol) echo request packets and analyzing the responses. Ping is a fundamental network diagnostic tool that helps test connectivity, measure latency, and troubleshoot network issues. Syntax #include #include #include int socket(int domain, int type, int protocol); int sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen); How Ping Works Ping operates by sending ICMP echo request packets to a ...
Read More