Find Politeness of a Number in C++

sudhir sharma
Updated on 16-Mar-2021 05:08:54

174 Views

In this problem, we are given a positive integer N. Our task is to find the politeness of a number.Polite Number is a number which can be expressed as a sum of two or more consecutive numbers.Politeness of a number is defined as the number of ways the number can be expressed as sum of consecutive integers.Let’s take an example to understand the problem, Inputn = 5Output1Explanation2 + 3 = 5, is the only consecutive sum.Solution ApproachA simple solution to the problem is to check all consecutive numbers till N and if their sum is equal to N, increase count ... Read More

Find Perimeter of Shapes in Binary Matrix using C++

sudhir sharma
Updated on 16-Mar-2021 05:06:43

288 Views

In this problem, we are given a binary matrix bin[][] of size nXm consisting of 0’s and 1’s only. Our task is to Find perimeter of shapes formed with 1s in a binary matrix.The perimeter taken will cover the figure from all sides, i.e.For 1 single value, the perimeter is 4.Let’s take an example to understand the problem, Inputbin[][] = [1, 0] [1, 0]Output6ExplanationThe cells (0, 0) and (1, 0) are connected making a rectangle of sides 2 and 1. The perimeter is 6.Solution ApproachA simple solution to the problem is simply finding all one and their ... Read More

Find Perimeter of a Triangle in C++

sudhir sharma
Updated on 16-Mar-2021 05:04:14

3K+ Views

In this problem, we will see the perimeter of a triangle, formula for the perimeter of different types of triangle and program to find them.Perimeter is defined as the total distance about the figure. Basically, it is the sum of all sides of the given figure.Perimeter of a triangleThe perimeter of a triangle is the sum of all its three sides (triangle is a three sides figure).Formula, Perimeter = sum of all sidesPerimeter = x + y + zProgram to find the perimeter of a triangle, Example Live Demo#include using namespace std; int calcPerimeter(int x, int y, int z ){ ... Read More

Find Pairs in Array Whose Sums Exist in Array in C++

sudhir sharma
Updated on 16-Mar-2021 04:57:22

335 Views

In this problem, we are given an array arr[] consisting of N integer. Our task is to find pairs in an array whose sums already exist in the array. We need to find pairs with sum value = a value in the arrayLet’s take an example to understand the problem, Inputarr[] = {1, 2, 4, 6, 7}Output(1, 6), (2, 4)ExplanationFor pairs (1, 6), the sum of values is 7 which is present in the array.For pairs (2, 4), the sum of values is 6 which is present in the array.Solution ApproachA simple solution to the problem is by finding all ... Read More

Find Other Two Sides of a Right Angle Triangle in C++

sudhir sharma
Updated on 16-Mar-2021 04:54:20

292 Views

In this problem, we are given an integer a denoting one side of a right angle triangle. We need to check whether it is possible to have a right angle triangle with side a. If it is possible, then find the other two sides of a right angle triangle.Let’s take an example to understand the problem, Inputa = 5OutputSides : 5, 12, 13ExplanationThe sides of right angle are found as 52 + 122 = 132Solution ApproachA simple solution to the problem is using pythagoras theorem. We know that the sides of a right angled triangle follow pythagoras theorem, which isa2 ... Read More

Find Other Two Sides and Angles of a Right Angle Triangle in C++

sudhir sharma
Updated on 16-Mar-2021 04:52:08

546 Views

In this problem, we are given an integer a denoting one side of a right angle triangle. We need to check whether it is possible to have a right angle triangle with side a. If it is possible, then find the other two sides and angle of a right angle triangle.Let’s take an example to understand the problem, Inputa = 5OutputSides : 5, 12, 13 Angles : 67.38, 22.62, 90ExplanationThe sides of right angle are found as 52 + 122 = 132 And using these sides we can find the angles are, Sin-1 (5/13) and 90 - Sin-1 (5/13).Solution ApproachA ... Read More

Find Orientation of a Pattern in a Matrix in C++

sudhir sharma
Updated on 16-Mar-2021 04:48:58

179 Views

In this problem, we are given a matrix consisting of character values that make a pattern, we are also given a pattern to be found. Our task is to find the orientation (horizontal or vertical) of a pattern in a matrix.Let’s take an example to understand the problem, Inputmat[][] = {    { r, a, m },    {a, m, c},    {w, f, t} } Patern : rawOutputverticalSolution ApproachA simple solution to the problem is by searching the M sized pattern in all the N rows of the matrix. This solution is ok but a more effective solution to ... Read More

Find Numbers with K Odd Divisors in a Given Range

sudhir sharma
Updated on 16-Mar-2021 04:45:02

247 Views

In this problem, we are given three integer values, L, R, and k. Our task is to find numbers with K divisors in a given range. We will be finding the count of numbers in the range [L, R] that have exactly k divisors. We will be counting the 1 and the number itself as a divisor.Let’s take an example to understand the problem, Inputa = 3, b = 10, k = 4Output2ExplanationNumbers with exactly 3 divisors within the range 3 to 10 are 6 : divisors = 1, 2, 3, 6 8 : divisors = 1, 2, 4, 8Solution ... Read More

Scope Rules Related to Functions in C Language

Bhanu Priya
Updated on 15-Mar-2021 15:22:35

750 Views

Scope rules are related to the following factors −Accessibility of a variables.Period of existence of a variable.Boundary of usage of variables.Scope rules related to functions are as followsFunction which is a self-contained block that performs a particular task.Variables that are declared within the function body are called local variables.These variables only exist inside the specific function that creates them. They are unknown to other functions and to the main functions too.The existence of local variables ends when the function completes its specific task and returns to the calling point.Example 1Following is the C program for scope rules related to functions ... Read More

Scope Rules Related to Statement Blocks in C Language

Bhanu Priya
Updated on 15-Mar-2021 15:21:54

204 Views

The scope rules are related to the following factors −Accessibility of a variables.Period of existence of a variable.Boundary of usage of variables.Scope rules related to statement blocks are given below −Block is enclosed in curly braces which consists of set of statements.Variables declared in a block are accessible and usable within that block and does not exist outside it.Example 1Following is the C program for scope rules related to statement blocks − Live Demo#include main ( ){    {       int i = 1;       printf ("%d", i);    }    {       int j=2;   ... Read More

Advertisements