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
Server Side Programming Articles
Page 950 of 2109
Print shortest path to print a string on screen in C Program.
Given a string, the program must display the shortest path which will print the string over the screen using that shortest path. The alphabets are arranged on a virtual keyboard in a 5x5 grid format. The keyboard layout is − A B C D E F G H I J K L M N O P Q R S T U V W X Y Z Syntax void printpath(char str[]); Algorithm The approach stores characters in a matrix and calculates the shortest path by − If row difference ...
Read MorePrint sorted distinct elements of array in C language
Given an array of integer elements, the task is to remove duplicate values and print the distinct elements in sorted order. For example, given an array that stores values {4, 6, 5, 3, 4, 5, 2, 8, 7, 0}, we need to identify unique elements and sort them. The final result should be {0, 2, 3, 4, 5, 6, 7, 8}. Original Array: 4 6 ...
Read MorePrint numbers with digits 0 and 1 only such that their sum is N in C Program.
Given an integer n, the task is to print numbers consisting only of digits 0 and 1 whose sum equals n. The valid numbers containing only zeros and ones are: 1, 10, 11, 100, 101, 110, 111, etc. We need to find a combination of these numbers that adds up to n. For example, if n = 31, possible combinations are: 10+10+11 = 31 or 10+10+10+1 = 31. Syntax void findNumbers(int n); Algorithm The algorithm uses a greedy approach − Start with the given number n While n > 0, check ...
Read MorePrint symmetric double triangle pattern in C language
In C, printing a symmetric double triangle pattern involves creating a diamond-like structure using alternating X and O characters. This pattern consists of three main sections: upper half, middle line, and lower half. Syntax void printPattern(int n); void printX(int count); void printO(int count); Pattern Structure The symmetric double triangle pattern contains three parts − Upper half: n-1 lines for odd n or n-2 lines for even n Middle line: 1 line for odd n or 3 lines for even n Lower half: n-1 lines for odd n or n-2 lines for even ...
Read MorePrint nodes of linked list at given indexes in C language
In C programming, printing nodes of a linked list at given indexes involves traversing the list and accessing elements at specific positions. Unlike arrays, linked lists don't have direct indexing, so we must traverse from the head node counting positions until we reach the desired index. Syntax void printAtIndex(struct node* head, int index); void printMultipleIndexes(struct node* head, int indexes[], int size); Example 1: Print Single Node at Given Index This example demonstrates how to print a node at a specific index − #include #include struct node { ...
Read MorePrint n x n spiral matrix using O(1) extra space in C Program.
We are given a positive integer n and need to create a spiral matrix of n x n using only O(1) extra space in clockwise direction. A spiral matrix starts from the center and fills values in a spiral pattern outward. The spiral matrix fills values in clockwise direction starting from the center. For example, a 3x3 matrix would fill as: center → right → down → left → up and so on. ...
Read MorePrint the last k nodes of the linked list in reverse order Recursive Approaches in C language
In C programming, printing the last k nodes of a linked list in reverse order using recursion is an elegant approach that leverages the function call stack. This technique traverses the entire list recursively and then prints the nodes during the return phase of recursion. Syntax void printLastKNodesReverse(struct node* head, int* count, int k); Algorithm The recursive algorithm works in two phases − Forward traversal: Recursively traverse to the end of the list Backward counting: During return, increment counter and print nodes if count ≤ k Linked ...
Read MorePrint the alternate nodes of linked list (Iterative Method) in C language
In this problem, we need to print alternate nodes from a linked list, which means printing every other node starting from the first node. The iterative method uses loops to traverse the linked list and prints nodes at even positions (0th, 2nd, 4th, etc.). For example, if the list contains nodes 29, 34, 43, 56, and 88, the output will be alternate nodes: 29, 43, and 88. 29 34 43 ...
Read MorePrint numbers in matrix diagonal pattern in C Program.
In C programming, we can create a matrix pattern where numbers are filled in diagonal order. This pattern fills elements starting from the top-left corner, moving diagonally down and to the right. .cell { fill: #f0f0f0; stroke: #333; stroke-width: 1; } .text { font-family: Arial; font-size: 14px; text-anchor: middle; dominant-baseline: middle; } .arrow { stroke: #007acc; stroke-width: 2; fill: none; marker-end: url(#arrowhead); } .diagonal { stroke: ...
Read MorePrint middle level of perfect binary tree without finding height in C language
In C, printing the middle level of a perfect binary tree without calculating its height is achieved using a two-pointer technique. This approach uses two traversal pointers moving at different speeds to identify when we reach the middle level. A perfect binary tree is one where all interior nodes have exactly two children and all leaf nodes are at the same level. 12 21 32 41 ...
Read More