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 Sunidhi Bansal
Page 10 of 81
Print matrix in zag-zag fashion in C Programming.
In C programming, printing a matrix in zig-zag fashion means traversing the matrix diagonally while alternating the direction of traversal. This creates a zig-zag pattern where elements are visited along diagonals, first from top-left to bottom-right, then from bottom-right to top-left, and so on. 10 20 30 40 50 ...
Read MorePrint matrix in snake pattern from the last column in C Programming.
In C, printing a matrix in snake pattern from the last column means traversing the matrix row by row, alternating the direction of column traversal. For odd-numbered rows (index 0, 2, 4...), we print from right to left, and for even-numbered rows (index 1, 3, 5...), we print from left to right. Matrix Snake Pattern from Last Column 10 20 30 40 ...
Read MorePrint matrix in snake pattern in C Programming.
In C programming, printing a matrix in snake pattern means traversing the matrix row by row where even-indexed rows are printed from left to right and odd-indexed rows are printed from right to left. This creates a snake-like zigzag pattern through the matrix elements. ...
Read MorePrint 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 More