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 Programming Language Standard
In this article, we will learn about the standards defined in the C programming language. These standards specify how programs should be compiled and executed as defined by the development community. To understand this concept, let's examine a common C program that demonstrates standard compliance issues − What is the C Programming Language Standard? The C programming language standard defines the official specification for how C compilers should behave. It establishes the correct syntax, semantics, and behavior of C programs. The latest C standard is ISO/IEC 9899:2018, also known as C18, which was released in June 2018. ...
Read MoreC program to store Student records as Structures and Sort them by Name
In this problem, we are given a student's record which contains student_id, student_name, and student_percentage. Our task is to create a C program to store student records as structures and sort them by name using string comparison. Syntax struct Student { int student_id; char student_name[50]; int student_percentage; }; int qsort(void *base, size_t nitems, size_t size, int (*compar)(const void *, const void*)); Example Input and Output Input − student record − { student_id = 1, student_name = Nupur, student_percentage = ...
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 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 More