Server Side Programming Articles

Page 950 of 2109

Print shortest path to print a string on screen in C Program.

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 370 Views

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 More

Print sorted distinct elements of array in C language

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 634 Views

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 More

Print numbers with digits 0 and 1 only such that their sum is N in C Program.

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 434 Views

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 More

Print symmetric double triangle pattern in C language

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 474 Views

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 More

Print nodes of linked list at given indexes in C language

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 6K+ Views

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 More

Print n x n spiral matrix using O(1) extra space in C Program.

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 573 Views

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 More

Print the last k nodes of the linked list in reverse order Recursive Approaches in C language

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 216 Views

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 More

Print the alternate nodes of linked list (Iterative Method) in C language

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 1K+ Views

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 More

Print numbers in matrix diagonal pattern in C Program.

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 3K+ Views

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 More

Print middle level of perfect binary tree without finding height in C language

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 304 Views

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
Showing 9491–9500 of 21,090 articles
« Prev 1 948 949 950 951 952 2109 Next »
Advertisements