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
Articles by sudhir sharma
Page 10 of 98
C 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 MoreC Program for Matrix Chain Multiplication
In this problem, we are given a sequence (array) of dimensions that define a chain of matrices. Our task is to create a C program for Matrix chain multiplication to find the minimum number of scalar multiplications required to multiply these matrices. The array of matrices will contain n elements, which define the dimensions of the matrices as arr[i-1] × arr[i] for the i-th matrix. Syntax int matrixChainOrder(int dimensions[], int n); Understanding the Problem Let's take an example to understand the problem − Input array[] = {3, 4, 5, 6} ...
Read MoreC program to detect tokens in a C program
Here, we will create a C program to detect tokens in a C program. This is called the lexical analysis phase of the compiler. The lexical analyzer is the part of the compiler that detects the token of the program and sends it to the syntax analyzer. Token is the smallest entity of the code. It can be a keyword, identifier, constant, string literal, or symbol. Syntax void detectTokens(char* sourceCode); Types of Tokens Examples of different types of tokens in C − Keywords: for, if, include, while, int, etc. Identifiers: variables, ...
Read MoreC program to demonstrate fork() and pipe()
In this problem, we will demonstrate fork() and pipe(). Here we will create a C program for Linux that will concatenate two strings, using 2 processes − one will take input and send it to another which will concatenate the string with a predefined string and return the concatenated string. Note: This program requires a Unix-like system (Linux/macOS) with support for fork() and pipe() system calls. It will not compile on Windows unless using WSL or similar environment. Fork() and Pipe() Overview fork() − creates a child process. This child process has a new PID ...
Read MoreProgram for Rabin-Karp Algorithm for Pattern Searching in C
In this problem, we are given two strings − a text and a pattern. Our task is to create a program for Rabin-Karp algorithm for pattern search, which will find all the occurrences of the pattern in the text string. The Rabin-Karp algorithm is an efficient string matching algorithm that uses hashing to find patterns. It works by computing hash values for the pattern and text windows, comparing them first before doing character-by-character matching. Syntax void rabinKarpSearch(char pattern[], char text[]); // Where pattern is the string to search for // And text is the string to ...
Read MoreC Program for KMP Algorithm for Pattern Searching
In this problem, we are given two strings a text and a pattern. Our task is to create a program for KMP algorithm for pattern search, it will find all the occurrences of pattern in text string. The KMP (Knuth Morris Pratt) algorithm is an efficient string matching algorithm that preprocesses the pattern to avoid unnecessary comparisons. It uses a failure function to skip characters when a mismatch occurs. Syntax void KMPSearch(char* text, char* pattern); void computeLPSArray(char* pattern, int M, int* lps); How KMP Algorithm Works The KMP algorithm works in two phases ...
Read MoreC Program for Anagram Substring Search
In this problem, we are given two strings: one text of size n and another pattern of size m. Our task is to create a program for anagram substring search. Here, we have to find all occurrences of the pattern and all its permutations (anagrams) in the text. An anagram is a word formed by rearranging the letters of another word. Let's take an example to understand the problem − Input text = "xyztrwqyzxfg" pattern = "xyz" Output Found at index 0 Found at index 7 Algorithm ...
Read More