Sunidhi Bansal

Sunidhi Bansal

809 Articles Published

Articles by Sunidhi Bansal

Page 76 of 81

Print symmetric double triangle pattern in C language

Sunidhi Bansal
Sunidhi Bansal
Updated on 22-Aug-2019 453 Views

Given with number of lines the program must print the symmetric double triangle pattern with least complexity.ExampleInput: 5 Output:  X           X           O X            O X     X O X O X        X O         X O          X           XThe entire problem contains 3 different partitions −Print upper half with n-1 lines for odd n or n-2 lines for even n.Print middle lines, 1 line for odd n or ...

Read More

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

Sunidhi Bansal
Sunidhi Bansal
Updated on 22-Aug-2019 351 Views

Given a string, the program must display the shortest path which will print the string over the screen using that shortest path.Like screen will store alphabets in the formatA B C D E F G H I J K L M N O P Q R S T U V W X Y ZExampleInput: HUP Output : Move Down Move Down Move Down destination reached Move Left Move Left Move Down Move Down Move Down destination reached Move Up destination reachedThe approach used here is to store the characters in the n x n matrix and perform the following operation ...

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 22-Aug-2019 403 Views

Given an integer n, the task is to print the numbers who consist only 0’s and 1’s and their sum is equal to the integer n.The numbers which contain only zeros and ones are 1, 10, 11 so we have to print all those numbers which can be added to form the sum equal to n.Like, we entered n = 31 then the answer can be 10+10+11 or 10+10+10+1 theExampleInput: 31 Output:10 10 10 1Algorithmint findNumbers(int n) START STEP 1: DECLARE AND ASSIGN VARAIBALES m = n % 10, a = n STEP 2: LOOP WHILE a>0    IF a/10 ...

Read More

Print sorted distinct elements of array in C language

Sunidhi Bansal
Sunidhi Bansal
Updated on 22-Aug-2019 612 Views

Given with an array of integer elements, the task is to remove the duplicate values and print the distinct elements in sorted manner.Given below is an array that stores integer type values in the fashion 4, 6, 5, 3, 4, 5, 2, 8, 7 and 0 now, the result will print the sorted elements as 0, 2, 3, 4, 4, 5, 5, 6, 7 and 8 but this result still contains duplicate values 4 and 5 which should be removed and the final result will be 0, 2, 3, 4, 5, 6, 7 and 8ExampleInput: array[] = {4, 6, 5, ...

Read More

Print nodes of linked list at given indexes in C language

Sunidhi Bansal
Sunidhi Bansal
Updated on 22-Aug-2019 6K+ Views

We have to print the data of nodes of the linked list at the given index. Unlike array linked list generally don’t have index so we have to traverse the whole linked list and print the data when we reached a particular.Let’s say, list contains the nodes 29, 34, 43, 56 and 88 and the value of indexes are 1, 2 and 4 than the output will be the nodes at these indexes that are 34, 43 and 88.ExampleLinked list: 29->34->43->56->88 Input: 1 2 4 Output: 34 43 88In above representation of Linked List the yellow highlighted nodes are the ...

Read More

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

Sunidhi Bansal
Sunidhi Bansal
Updated on 22-Aug-2019 540 Views

We are given an positive integer n and make a spiral matrix of n x n, with only using O(1) extra space in clockwise directionSpiral matrix is a matrix that works like a spiral which will start from the origin of a circle and rotates in clockwise fashion. So the task is to print the matrix in spiral form using O(1) space starting from 2 → 4 → 6 → 8 → 10 → 12 → 14 → 1 6→ 18.Given below is the example of spiral matrix −ExampleInput: 3 Output:    9 8 7    2 1 6   ...

Read More

Print numbers in matrix diagonal pattern in C Program.

Sunidhi Bansal
Sunidhi Bansal
Updated on 22-Aug-2019 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 the last k nodes of the linked list in reverse order Recursive Approaches in C language

Sunidhi Bansal
Sunidhi Bansal
Updated on 22-Aug-2019 194 Views

The task is to print the k nodes starting from the end of the linked list using recursive approach.Recursive approach is the one in which the function call itself again and again till the call is being made and hence stores the result.Let’s say, list contains the nodes 29, 34, 43, 56 and 88 and the value of k is 2 than the output will be the last k nodes such as 56 and 88.ExampleLinked List: 29->34->43->56->88 Input: 2 Output: 88 56As specified the recursive approach should be used which will traverse the list from the end keeping track of ...

Read More

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

Sunidhi Bansal
Sunidhi Bansal
Updated on 22-Aug-2019 1K+ Views

In this problem, program must print the alternates from the given linked list that is leaving one printing other and so on using iterative method.Iterative method is the one which generally uses loops that are executed till the condition holds value 1 or true.Let’s say, list contains the nodes 29, 34, 43, 56 and 88 and than the output will be the alternate nodes such as 29, 43 and 88.ExampleInput: 29->34->43->56->88 Output: 29 43 88The approach is to traverse the entire list till the last node. While, traversing a counter variable can be taken which is incremented to 1 and ...

Read More

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

Sunidhi Bansal
Sunidhi Bansal
Updated on 22-Aug-2019 297 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
Showing 751–760 of 809 articles
« Prev 1 74 75 76 77 78 81 Next »
Advertisements