sudhir sharma

sudhir sharma

975 Articles Published

Articles by sudhir sharma

Page 14 of 98

_Generic keyword in C ? 1: 20

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 910 Views

The _Generic keyword in C is used to define type-generic macros that can work with different data types. This keyword was introduced in the C11 standard to enable compile-time type selection, allowing a single macro to behave differently based on the type of its argument. Syntax #define macro_name(x) _Generic((x), \ type1: expression1, \ type2: expression2, \ default: default_expression \ )(x) The _Generic expression evaluates to one of the specified expressions based on the type of the controlling expression (x). Parameters ...

Read More

A Product Array Puzzle in C?

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 385 Views

A Product Array Puzzle is a common programming problem where we need to construct an array such that each element contains the product of all elements in the original array except the element at that position. The constraint is that we cannot use the division operator. Syntax void productArray(int arr[], int n, int result[]); // arr[] - input array // n - size of array // result[] - output array containing products Approach: Using Left and Right Product Arrays The solution uses two auxiliary arrays to store products of elements to the ...

Read More

C Program to find IP Address, Subnet Mask & Default Gateway

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 1K+ Views

C programming language can be used to find the details of the Internet connection of the system. Now, let's learn about the basic terms that we need in this problem. IP Address − IP Address stands for Internet Protocol address. An IP address is a fixed numerical identification number that is associated with each device. IP address allows communication of your device using IP address over the internet. Subnet Mask − A 32-bit component of the IP address. The subnet mask differentiates the network component of IP address into two parts. One being network address and other being ...

Read More

C Program to find direction of growth of stack

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 810 Views

A stack is a data structure that stores elements in memory. The stack can grow in two directions: upward (toward higher memory addresses) or downward (toward lower memory addresses). This direction depends on the system architecture and compiler implementation. When functions are called, local variables are allocated on the stack. By comparing the memory addresses of local variables in different function calls, we can determine the stack's growth direction. Syntax void function_name(int *address_pointer); // Compare addresses using pointer arithmetic if (address1 < address2) { /* stack direction logic */ } Algorithm Step ...

Read More

C program to compare two files and report mismatches

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 9K+ Views

In C programming, we can access files and read their content to perform various operations. Comparing two files character by character helps identify differences between similar documents. This program compares two text files and reports any mismatches found, including the line number and position where the first difference occurs. Syntax FILE *fopen(const char *filename, const char *mode); int getc(FILE *stream); int fclose(FILE *stream); Algorithm Step 1: Open both files with read mode Step 2: Read characters one by one from both files simultaneously Step 3: Compare characters and track line numbers and ...

Read More

C program that does not suspend when Ctrl+Z is pressed

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 1K+ Views

In C programming, when a program malfunctions or runs indefinitely, programmers can explicitly stop execution using keyboard shortcuts. Understanding how to handle or override these signals is crucial for creating robust applications. There are two primary keyboard shortcuts used to control program execution − Ctrl+C − Sends a SIGINT signal to terminate the program immediately. This signal can be handled using the signal() function in C. Ctrl+Z − Sends a SIGTSTP signal to suspend the program execution. This signal is more powerful and can also be intercepted and handled. Here, we will create a C ...

Read More

C Program for Reversal algorithm for array rotation

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 3K+ Views

An algorithm is a set of instructions that are performed in order to solve the given problem. Here, we will discuss the reversal algorithm for array rotation and create a program for a reversal algorithm. Now, let's get to some terms that we need to know to solve this problem − Array − A container of elements of the same data type. The size (number of elements) of the array is fixed at the time of the declaration of the array. Array rotation − Rotating an array is changing the order of the elements of the array. ...

Read More

Find the area of a circle in C programming.

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 13K+ Views

A circle is a closed figure where all points are equidistant from a central point called the center. The distance from the center to any point on the circle is called the radius. To find the area of a circle in C programming, we use the mathematical formula and implement it with proper input handling. Syntax area = π * radius * radius Where π (pi) ≈ 3.14159 and radius is the distance from center to the edge of the circle. Method 1: Using Fixed Radius Value This example calculates the area using ...

Read More

C Program for Number of stopping station problem

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 641 Views

The number of stopping stations problem calculates the ways a train can stop at r stations out of n total stations such that no two stopping stations are consecutive. This is a classic combinatorial problem solved using the formula for selecting non-adjacent elements. Syntax C(n-r+1, r) = (n-r+1)! / (r! * (n-2*r+1)!) Problem Explanation When a train travels from point X to Y with n intermediate stations, we need to find the number of ways to select r stopping stations such that no two selected stations are adjacent. This constraint transforms the problem into ...

Read More

Add two numbers represented by two arrays in C Program

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 2K+ Views

A number represented by an array is stored in such a form that each digit of the number is represented by an element of the array. For example − Number 234 in array is {2, 3, 4} To add two such numbers we will first add digits from the least significant position and if the sum is greater than 9, we propagate the carry. We continue this process for consecutive digits until all digits are processed. Syntax void addArrays(int arr1[], int arr2[], int size1, int size2, int result[]); Algorithm To ...

Read More
Showing 131–140 of 975 articles
« Prev 1 12 13 14 15 16 98 Next »
Advertisements