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

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

284 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

536 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

170 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

237 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

722 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

193 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

What is a Two-Dimensional Array in C Language

Bhanu Priya
Updated on 15-Mar-2021 15:11:52

4K+ Views

An array is a group of related items that store with a common name.SyntaxThe syntax is as follows for declaring an array −datatype array_name [size];Types of arraysArrays are broadly classified into three types. They are as follows −One – dimensional arraysTwo – dimensional arraysMulti – dimensional arraysInitializationAn array can be initialized in two ways, which are as follows −Compile time initialization.Runtime initialization.Two multidimensional arraysThese are used in situations where a table of values have to be stored (or) in matrices applications.SyntaxThe syntax is given below −datatype array_ name [rowsize] [column size];For example int a[5] [5];a[0][0]10a[0][1]20a[0][2]30a[1][0]40a[1][1]50a[1][2]60a[2][0]a[2][1]a[2][2]Following is the C Program for ... Read More

One-Dimensional Array in C Language

Bhanu Priya
Updated on 15-Mar-2021 15:06:17

12K+ Views

An array is a group of related items that store with a common name.SyntaxThe syntax is as follows for declaring an array −datatype array_name [size];Types of arraysArrays are broadly classified into three types. They are as follows −One – dimensional arraysTwo – dimensional arraysMulti – dimensional arraysOne – dimensional arrayThe Syntax is as follows −datatype array name [size]For example, int a[5]InitializationAn array can be initialized in two ways, which are as follows −Compile time initializationRuntime initializationExampleFollowing is the C program on compile time initialization − Live Demo#include int main ( ){    int a[5] = {10, 20, 30, 40, 50};   ... Read More

C Program to Reverse an Array

Bhanu Priya
Updated on 15-Mar-2021 15:04:15

3K+ Views

An array is a group of related items that store with a common name.SyntaxThe syntax is as follows for declaring an array −datatype array_name [size];InitializationAn array can also be initialized at the time of declaration −int a[5] = { 10, 20, 30, 40, 50};Reversing array in CWe can reverse array by using swapping technique.For example, if 'P' is an array of integers with four elements −P[0] = 1, P[1] = 2, P[2] = 3 and P[3]=4Then, after reversing −P[0] = 4, P[1] = 3, P[2] = 2 and P[3]=1ExampleFollowing is the C program to reverse an array −#include int ... Read More

Find Highest Common Factor (HCF) and Least Common Multiple (LCM) in C

Bhanu Priya
Updated on 15-Mar-2021 15:02:48

6K+ Views

First, let us learn how to find Highest Common Factor (HCF).Highest Common Factor (HCF)The greatest number divides each of the two or more numbers is called HCF or Highest Common Factor. It is also called as Greatest Common Measure(GCM) and Greatest Common Divisor(GCD).For example, What is the HCF of 12 and 16?Factors of 12 = 1, 2, 3, 4, 6, 12. Factors of 16=1, 2, 4, 8, 16Highest common factor (H.C.F) of 12 and 16 = 4.Least Common Multiple (LCM)For two integers x and y, denoted LCM(x, y), it is the smallest positive integer that is divisible by both x ... Read More

Advertisements