Found 26504 Articles for Server Side Programming

C++ Program to find the smallest digit in a given number

Dev Prakash Sharma
Updated on 23-Feb-2021 19:39:23

4K+ Views

Given a non-negative number, the task is to find its smallest digit.For exampleInput:N = 154870Output:0Explanation: In the given number '154870', the smallest digit is '0'.Approach to Solve this ProblemThe simplest approach to solve this problem is to extract the last digit in the given number using the remainder theorem. While traversing the number, we will check if the extracted digit is less than the last digit, then return the output.Take a number n as the input.An integer function smallest_digit(int n) takes 'n' as the input and returns the smallest digit in the given number.Now initialize min as the last digit of the ... Read More

C++ Program to Check Whether a given Binary Tree is a Full Binary Tree or not

Dev Prakash Sharma
Updated on 23-Feb-2021 19:41:10

2K+ Views

Given a Binary Tree, the task is to check whether it is a Full Binary Tree or not. A Binary Tree is said to be a Full Binary Tree if every node has zero or two children.For ExampleInput-1Output:1Explanation: Every node except the leaf node has two children, so it is a full binary tree.Input-2: Output:0Explanation: Node 2 has only one child, so it is not a full binary tree.Approach to Solve this ProblemTo check whether a given binary tree is full or not, we can check recursively for the left subtree and right subtree.Input a given Binary Tree having nodes and its children.A ... Read More

Check if an array is sorted and rotated in C++

Ravi Ranjan
Updated on 06-Jun-2025 19:15:03

2K+ Views

A sorted and rotated array is an array that is sorted in ascending or descending order and then rotated either left or right by a specific number of elements. There should exist exactly one pivot point around which the array is rotated. The array can be said to be split into two halves and each half is a sorted array. For example: {5, 6, 7, 1, 2, 3} is a sorted and rotated array and {5, 6, 7, 8, 2, 5, 4, 5} is not a sorted and rotated array. In this article, our task is to check if the ... Read More

Check if a Tree is Isomorphic or not in C++

Dev Prakash Sharma
Updated on 23-Feb-2021 04:50:26

386 Views

In a binary tree, each node contains two children, i.e., left child and right child. Let us suppose we have two binary trees and the task is to check if one of the tree can be obtained by flipping another tree by left of it or not.A Tree is Isomorphic if it can be obtained by flipping the other tree in its left side.For ExampleInput-1Output: IsomorphicExplanation: The given Tree-2 can be obtained by flipping the Tree-1 in the left side, thus the Tree is isomorphic.Approach to Solve this ProblemA recursive approach to solve this particular problem is that a Boolean function will ... Read More

Breadth First Search on Matrix in C++

Dev Prakash Sharma
Updated on 23-Feb-2021 04:49:36

1K+ Views

In a given matrix, there are four objects to analyze the element position: left, right, bottom and top.Breadth First Search is nothing but finding the shortest distance between the two elements of a given 2-D Matrix. Thus in each cell, there are four operations we can perform which can be expressed in four numerals such as, '2' describes that the cell in the matrix is Source.'3' describes that the cell in the matrix is Destination.'1' describes that the cell can be moved further in a direction.'0' describes that the cell in the matrix can not be moved in any direction.On ... Read More

Binary Tree Tilt in C++

Dev Prakash Sharma
Updated on 23-Feb-2021 04:47:44

344 Views

Let us consider that we have the root node of a binary tree; the task is to find and return the sum of tilt of every node.The tilt of a binary tree is nothing but constructing the binary tree by finding the absolute difference of child nodes in the left subtree and the right subtree in each level. At some particular level, the nodes which don't have any child nodes, we simply tilt by replacing that node with zero.ExampleInputOutput: 15Explanation: Finding the tilt at every level of the given binary tree, The tilt of node 3 = 0The tilt of node ... Read More

Explain else-if ladder statement in C language

Mandalika
Updated on 22-Feb-2021 06:44:48

14K+ Views

This is the most general way of writing a multi-way decision.SyntaxRefer the syntax given below −if (condition1) stmt1; else if (condition2) stmt2; - - - - - - - - - - else if (condition n) stmtn; else stmt x;AlgorithmRefer the algorithm given below −START Step 1: Declare int variables. Step 2: Read a, b, c, d values at runtime Step 3: i. if(a>b && a>c && a>d) Print a is largest ii.else if(b>c && b>a && b>d) Print b is largest iii. else if(c>d && c>a && c>b) Print c is largest iv. else print d is largest STOPExampleFollowing ... Read More

Explain different types of expressions in C program

Bhanu Priya
Updated on 15-Mar-2021 10:24:50

4K+ Views

An expression is a combination of operators and operands which reduces to a single value. An operation is performed on a data item which is called an operand. An operator indicates an operation to be performed on data.For example, z = 3+2*1z = 5Primary expressions − It is an operand which can be a name, a constant or any parenthesized expression. Example − c = a+ (5*b);Postfix expressions − In a postfix expression, the operator will be after the operand. Example − ab+Prefix expressions − n a prefix expression, the operator is before the operand. Example − +abUnary expression − ... Read More

What are executable statements in C language?

Bhanu Priya
Updated on 15-Mar-2021 10:22:48

3K+ Views

A ‘C’ program contains executable statements. A compiler helps to translate the executable statements into machine language.When a user runs the program, he/she machines the language statements which are executed by the compiler.Types of executable statementsThe types of executable statements in C language are as follows −Input – output statementsAssignment statementsInput-output statementsStoring a value into memory is called ‘input operation’.After executing the computations, the results are stored in memory and the results can be displayed to the user by ‘output operation’.All i/o operations are performed using input / output functions.The most common I/O functions are supplied through the preprocessor directive ... Read More

Explain variable declaration and rules of variables in C language

Bhanu Priya
Updated on 15-Mar-2021 10:20:27

12K+ Views

Let us first understand, what is a variable.VariableIt is the name for memory location that may be used to store a data value.A variable may take different values at different times during execution.A variable name may be chosen by the programmer in a meaningful way, so as to reflect its function (or) nature in the program.For example, sum, avg, total etc.Rules for naming variableThe rules for naming a variable are explained below −They must begin with a letter.Maximum length of variable is 31 characters in ANSI standard. But, first eight characters are significant by many compilers.Upper and lowercase characters are ... Read More

Advertisements