Server Side Programming Articles - Page 2191 of 2650

Print numbers in matrix diagonal pattern in C Program.

Sunidhi Bansal
Updated on 22-Aug-2019 08:54:13

3K+ Views

The task is to print the matrix of n x n of the diagonal pattern.If n is 3 then to print a matrix in Diagonal pattern is −So the output will be like −ExampleInput: 3 Output:    1 2 4    3 5 7    6 8 9 Input: 4 Output:    1 2 4  7    3 5 8 11    6 9 12 14    10 13 15 16The problem suggests we have to give a number n and generate a matrix of n x n and then we have to traverse the matrix in a diagonal pattern ... Read More

Print reverse of a Linked List without actually reversing in C language

Sunidhi Bansal
Updated on 22-Aug-2019 08:48:12

352 Views

The task is to print the reverse of a given linked list by using recursive function. The program must print the reverse but not reverse the list that means the order of the nodes remains the sameHere, the program will move head pointer containing the address of a first node to next node until the NULL is examined which is stored in last node of a list and printing the data of a head node.ExampleInput: 29 34 43 56 Output: 56 43 34 29Firstly, the nodes are inserted into the list and a pointer will start pointing to the nodes ... Read More

Print Right View of a Binary Tree in C language

Sunidhi Bansal
Updated on 22-Aug-2019 08:45:40

417 Views

The task is to print the right nodes of a given binary tree. Firstly user will insert data for creating a binary tree and than print right view of the tree so formed.The above diagram showcase the binary tree created with the nodes 10, 42, 93, 14, 35, 96, 57 and 88 amongst these nodes the one that lies in the right side of a tree are chosen and displayed over the screen. For example, 10, 93, 57 and 88 are the rightmost nodes of a binary tree.ExampleInput : 10 42 93 14 35 96 57 88 Output : 10 ... Read More

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

Sunidhi Bansal
Updated on 22-Aug-2019 08:43:00

247 Views

The program should print the middle level of a binary tree e.g. if there are 4 levels in a binary tree than the program must print the level 2 nodes but the demand here is to calculate the level without finding the height.Perfect binary tree is a tree in which interior nodes must have two children and all leave nodes should be at the same level or depth.Here, Interior nodes 21 and 32 both are having childrenLeaf nodes are 41, 59, 33 and 70 all lies at the same level.Since it is satisfying both the properties it’s a perfect binary ... Read More

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

Sunidhi Bansal
Updated on 22-Aug-2019 08:45:50

256 Views

According to the problem we are given an array of n positive integers, we have to find a pair with maximum AND value from the array.ExampleInput: arr[] = { 4, 8, 12, 16 } Output: pair = 8 12 The maximum and value= 8 Input:arr[] = { 4, 8, 16, 2 } Output: pair = No possible AND The maximum and value = 0For finding Maximum AND value is similar to find out Maximum AND value in an array. Program must find out the pair of elements resulting in obtained AND value. For finding the elements, simply traverse the ... Read More

Print Leaf Nodes at a given Level in C language

Sunidhi Bansal
Updated on 22-Aug-2019 08:35:39

1K+ Views

The task involves printing leaf nodes of a binary tree at given level k which is specified by the user.Leaf nodes are the end nodes whose left and right pointer is NULL which means that particular node is not a parent node.ExampleInput : 11 22 33 66 44 88 77 Output : 88 77Here, k represents the level of a tree which needs to be printed. The approach used here is traversing every node and checking whether the node is having any pointer. Even if there is one pointer that means either left or right or both than that particular ... Read More

Print Left View of a Binary Tree in C language

Sunidhi Bansal
Updated on 22-Aug-2019 08:33:00

628 Views

The task is to print the left nodes of a given binary tree. Firstly user will insert data hence generating binary tree and than print left view of the tree so formed.Every node can have at most 2 child so here the program must traverse only the left pointer associated with a nodeIf left pointer is not null means it will have some data or pointer associated with it if not than it will be the left child to be printed and displayed as an output.ExampleInput : 1 0 3 2 4 Output : 1 0 2here, orange nodes represent ... Read More

Print the longest prefix of the given string which is also the suffix of the same string in C Program.

Sunidhi Bansal
Updated on 22-Aug-2019 08:36:54

1K+ Views

Given a string in which we have to check that the length of the longest prefix which is also a suffix of the string like there is a string “abcab” so here “ab” is of length 2 and is the longest substring with same prefix and suffix.ExampleInput: str[] = { “aabbccdaabbcc” } Output: 6 Input: abdab Output: 2If we will start the pointer from start and end of the string than they will get overlapped at some point so instead of doing that we will break the string from middle and start matching left and right string. If they are ... Read More

Print modified array after multiple array range increment operations in C Program.

Sunidhi Bansal
Updated on 22-Aug-2019 08:25:46

161 Views

Given an array arr[m] with m number of integers and n, which is the value to be added in an array and r queries are given with some start and end. For each query we have to add value n from the start till the end of the limit in an array.ExampleInput: arr[] = {1, 2, 3, 4, 5} query[] = { { 0, 3 }, { 1, 2 } } n = 2 Output: If we run above program then it will generate following output: Query1: { 3, 4, 5, 6, 5 } Query2: { 3, 6, 7, 6, ... Read More

Print lower triangular matrix pattern from given array in C Program.

Sunidhi Bansal
Updated on 22-Aug-2019 08:19:21

2K+ Views

Given with the matrix of n x n the task is to print that matrix of n x n in lower triangular pattern.Lower triangular matrix is a matrix which has elements below the principle diagonal including the principle diagonal elements and rest elements as zero.Let’s understand this with help of a diagram −Above the elements in green are the elements below the principle diagonal and the red elements are the elements above the principle diagonal which are set as zero.ExampleInput: matrix[3][3] = {    { 1, 2, 3 },    { 4, 5, 6 },    { 7, 8, 9 ... Read More

Advertisements