Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C Articles - Page 76 of 134
7K+ Views
Given with the threads the program must print the thread based on their priorities starting from 0 to 10.What is a thread?Thread is lightweight process that runs inside a program. A simple program can contain n number of threads.Unlike java, multithreading is not supported by the language standards, POSIX Threads (Pthreads) is the standard used in multithreading in C/C++. C does not contain any built-in support for multithreaded applications. Instead, it relies entirely upon the operating system to provide this feature.How it works in our program?To use the thread functions we use header file #include. This header file will include ... Read More
1K+ Views
Given a binary tree with left and right children and the task is to print the exact right and left child of the given tree.Leftmost nodes are the nodes which are associated on the left side from the parent node of the tree and rightmost nodes are which are associated on the right side from the parent node of the root.ExampleInput: 106 20 320 100 21 61 52 Output: 106 20 320 100 52AlgorithmStart Step 1 -> create structure of a node Declare int data Declare struct node *left and *right Step 2 -> create struct node* newNode(int ... Read More
643 Views
Given a matrix of NxN find a sub matrix of MxM where M=1 such that addition of all the elements of matrix MxM is maximum. Input of matrix NxN can contain zero, positive and negative integer values.ExampleInput: {{1, 1, 1, 1, 1}, {2, 2, 2, 2, 2}, {3, 3, 3, 3, 3}, {4, 4, 4, 4, 4}, {5, 5, 5, 5, 5} } Output: 4 4 5 5The above problem can be solved by a simple solution in which we can take whole matrix NxN, then find out all possible MxM matrix and ... Read More
188 Views
We are given an array of some size n and multiple integer values, we need to rotate an array from a given index k.We want to rotate an array from a index k like −ExamplesInput: arr[] = {1, 2, 3, 4, 5} K1 = 1 K2 = 3 K3 = 6 Output: 2 3 4 5 1 4 5 1 2 3 2 3 4 5 1AlgorithmSTART Step 1 -> Declare function void leftRotate(int arr[], int n, int k) Declare int cal = k% n Loop For int i=0 and i In ... Read More
217 Views
Given an array a[] containing N integers, the challenge is to print k different permutations of indices such that the values at those indices form a non-decreasing sequence. Print -1 if it is not possible.ExampleInput: arr[] = {2, 5, 6, 2, 2, 2, 2}, k = 4 Output: 0 3 4 5 6 1 2 3 0 4 5 6 1 2 0 3 4 5 6 1 2 3 0 4 5 6 1 2Sort the given array and keep track of the original indices of each element. That gives one required permutation. Now if ... Read More
158 Views
Given an array of size NxM where N number of rows and M number of columns, and the task is to print the number of zeroes in every column of a corresponding matrix after performing sort operation on the basis of number of zeros present in any column.For example if the 1st column contain 1 zeros and 2nd column doesn’t contain any number of zeros and 3rd column contain 2 zeroes then the result should be − 3 1 2.ExampleInput: 0 0 0 1 1 1 1 0 1 Output: 1 3 2ExplanationNote − the matrix is ... Read More
3K+ Views
Given an array of size 2X2 and the challenge is to print the sum of all the corner elements stored in an array.Assume a matrix mat[r][c], with some row “r” and column “c” starting row and column from 0, then its corner elements will be; mat[0][0], mat[0][c-1], mat[r-1][0], mat[r-1][c-1]. Now the task is to get these corner elements and sum those corner elements i.e., mat[0][0] + mat[0][c-1] + mat[r-1][0] + mat[r-1][c-1], and print the result on the screen.ExampleInput: Enter the matrix elements : 10 2 10 2 3 4 10 4 10 Output: sum of matrix is ... Read More
379 Views
Given four variables a, b, c, d with predefined values that will print the given bracket depending upon the variable used.Where variable, a for (( b for () c for )( d for ))The task is to use all the given brackets and print the balanced bracket expression, if we cannot form a balanced bracket expression then print -1. In case of multiple answers we can print any of the multiple answers which can be formed using the given brackets.ExampleInput: a = 3, b = 2, c = 4, d = 3 Output : (((((()()()()())))))()()To achieve this result we can, ... Read More
332 Views
Given an array a[] with elements and the task is to print the last occurrences of the given elements in the list. Here we not only have to remove the duplicate elements but also we have to maintain the order of the occurrences of the elements in an array as per the last time they have occurred.Like we have an array of 6 elements also containing some duplicate values i.e., {1, 3, 2, 3, 1, 2} so the result should be in form of 3 1 2.ExampleInput: a[]={4, 2, 2, 4, 1, 5, 1} Output : 2 4 5 1AlgorithmSTART ... Read More
482 Views
The task is to print the nodes starting from the end of the linked list without using extra space which means there shouldn’t be any extra variable instead the head pointer pointing the first node will be moved.ExampleInput: 10 21 33 42 89 Output: 89 42 33 21 10There can be many solutions to print the linked list in reverse order, like recursive approach (use extra space), reverse the linked list(requires modification in the given Linked List), pushing the elements on a stack and then pop and display the elements one by one(requires space O(n)), but these solutions seem to ... Read More