Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by sudhir sharma
Page 68 of 98
Arc length from given Angle in C++?
An Angle is formed when two rays meet at a point. The point on the plane at which these rays meet is vertex.Arc of a circle is a portion of the circumference that is described by an angle.In this problem, we are given an angle of the circle. And we need to find the length of arc using the given diameter of the circle. For example, Input : Angle = 45° Diameter = 28 Output : Arc = 11ExplanationLength of arc = (circumference) X (angle/360°)= (π * d)*(angle/360°)To make a program that calculates the length of Arc from the given ...
Read MoreAssociative arrays in C++
In c++ programming language, an associative array is a special type of array in which the index value can be of any data type i.e. it can be char, float, string, etc. These associative arrays are also known as maps or dictionaries. Also, the indexes are given a different name which is key and the data that is stored at the position of the key is value.So, we can define the associative array as a key-value pair.Let's define an associative array of bikes and their top speed.Bike top speed Ninja 290 S1000rr 310 Bullet 127 Duke 135 R1 286Example#include ...
Read MoreAverage of a stream of numbers in C++
Average of numbers is the sum of numbers divided by the total number of numbers.In this problem, we are given a stream of numbers. And we will print average of the number at every point.Let’s take an example of how it works −We have a stream of 5 number 24 , 76 , 29, 63 , 88The average at each point of the stream would be −24 , 50 , 43 , 48 , 56.For this we will find the average of the stream every time a number is added to the stream. So, we need to find the average ...
Read MoreAverage of max K numbers in a stream in C++
The average of number in a stream means calculating the average after every insertion. But in this problem, we need to find the average of max K numbers in a stream i.e. only k numbers of the array are considered for calculating the average. When we add a number if it is greater than any of the numbers that contribute to the average then only it is considered otherwise the average remains the same.Let’s take an example to understand the concept better −Input : n = 4 , k = 3 , array = { 4, 9, 1 , 5} ...
Read MoreBalance a string after removing extra brackets in C++
A string is an array of characters. In this problem, we are given a string which has opening and closing brackets. And we will balance this string by removing extra brackets from the string.Let’s take an example, Input : “)Tutor)ials(p(oin)t(...)” Output : “Tutorials(p(oin)t(...))”To solve this problem, we will traverse through the string and check for matching brackets. For unmatched brackets eliminate the closing brackets.AlgorithmStep 1 : Traverse the string from left to right. Step 2 : For opening bracket ‘(’ , print it and increase the count. Step 3 : For occurence of closing bracket ‘)’ , print it only ...
Read MoreBalanced Prime in C++
Balanced prime number is a prime number that has the same difference for its previous and next prime numbers. i.e. it is the mean of the nearest next prime and previous prime.For a prime number to be a balanced prime, it should follow the following formula −Pn = (P(n-1) + P(n+1)) / 2Where n is the index of the prime number pn in the ordered set of a prime number.The ordered set of prime numbers: 2, 3, 5, 7, 11, 13, ….First, balanced primes are 5, 53, 157, 173 , …In this problem, we are given a number n and ...
Read MoreBinary representation of a given number in C++
A binary number is a number that consists of only two digits 0 and 1. For example, 01010111.There are various ways to represent a given number in binary form.Recursive methodThis method is used to represent a number in its binary form using recursion.AlgorithmStep 1 : if number > 1. Follow step 2 and 3. Step 2 : push the number to a stand. Step 3 : call function recursively with number/2 Step 4 : pop number from stack and print remainder by dividing it by 2.Example#include using namespace std; void tobinary(unsigned number){ if (number > 1) tobinary(number/2); cout
Read MoreSum of squares of binomial coefficients in C++
The binomial coefficient is a quotation found in a binary theorem which can be arranged in a form of pascal triangle it is a combination of numbers which is equal to nCr where r is selected from a set of n items which shows the following formulanCr=n! / r!(n-r)! or nCr=n(n-1)(n-2).....(n-r+1) / r!The sum of the square of Binomial Coefficient i.e (nC0)2 + (nC1)2 + (nC2)2 + (nC3)2 + ……… + (nCn-2)2 + (nCn-1)2 + (nCn)2Input :n=5 Output:252ExplanationIn this program first we have to find the binomial coefficient of r which is selected from n set then we have to ...
Read MoreThe basic_string c_str function in C++ STL?
The basic_string c_str function that returns a pointer to an array of characters that is terminated using null character. It is an inbuilt method that has the value of a string that has null character termination.Syntax to define a c_str function in C++ −const Char ptr* c_str() constAbout the functionIt is an inbuilt method for the c++ STL library. No parameters can be passed to the method. It returns a char pointer. This pointer points to NULL terminated character array.Example#include #include using namespace std; int main() { string s = "I Love Tutorials Point"; int flag ...
Read MoreSum of squares of Fibonacci numbers in C++
Fibonacci series is a mathematical sequence of number which starts from 0 and the sum of two numbers is equal to the next upcoming number, for example, the first number is 0 and the second number is 1 sum of 0 and 1 will be 1F0=0, F1=1AndFn=Fn-1+Fn-2, F2=F0+F1 F2=0+1 F2=1then when we add number 1 and 1 then the next number will be 2F1=1, F2=1AndFn=Fn-1+Fn-2, F3=F1+F2 F3=1+1 F3=2Fibonacci sequence is 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, …We have to find the square of the fuel energy series and then we have to sum it and find ...
Read More