Programming Articles

Page 969 of 2547

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 439 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 475 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 580 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 225 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 306 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

Print pair with maximum AND value in an array in C Program.

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

In this problem, we are given an array of n positive integers and need to find a pair with the maximum AND value. The bitwise AND operation combines bits where both operands have 1 in the same position. Syntax int maxAND(int arr[], int n); int checkBit(int pattern, int arr[], int n); Algorithm Approach The algorithm works by building the maximum AND value bit by bit from the most significant bit (MSB) to the least significant bit (LSB). For each bit position, it checks if at least two numbers in the array have that bit ...

Read More

Print Leaf Nodes at a given Level in C language

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

In C programming, printing leaf nodes at a given level in a binary tree involves traversing the tree to a specific level and identifying nodes that have no children. A leaf node is a node whose both left and right pointers are NULL. Syntax void printLeafNodes(struct node* root, int level); Algorithm The approach uses recursive traversal − Base case: If root is NULL, return Target level: If level == 1, check if current node is a leaf Recursive case: If level > 1, recursively call for left and right subtrees with level-1 ...

Read More
Showing 9681–9690 of 25,466 articles
« Prev 1 967 968 969 970 971 2547 Next »
Advertisements