Find the Perimeter of a Cylinder in C++

Arnab Chakraborty
Updated on 04-Nov-2019 08:07:19

204 Views

Suppose we have the diameter and the height of the cylinder, we have to find the perimeter of the cylinder. As the perimeter is the outline of two dimensional object, then we cannot find the perimeter of one three dimensional object directly. We can make a cross section of the cylinder, and convert it as rectangle, then find the perimeter. The two sides of the rectangular cross section are the diameter, and the height. So perimeter is −p=(2*d)+(2*h)Example#include using namespace std; int getCylinderPerimeter(int d, int h) {    return (2*d) + (2*h); } int main() {    int diameter = ... Read More

char IsControl Method in C#

AmitDiwan
Updated on 04-Nov-2019 08:06:22

556 Views

The Char.IsControl(String, Int32) method in C# is used to indicate whether the character at the specified position in a specified string is categorized as a control character.Syntaxpublic static bool IsControl (string str, int index);Above, str is a string. The index parameter is the position of the character to evaluate in str.Let us now see an example to implement the Char.IsControl(String, Int32) method −Exampleusing System; using System.Globalization; public class Demo {    public static void Main(){       string val = "hjk9878hj";       Console.WriteLine("String = "+val);       UnicodeCategory unicode = Char.GetUnicodeCategory(val, 4);       Console.WriteLine("The ... Read More

Find Other End Coordinates of Diameter in a Circle using C++

Arnab Chakraborty
Updated on 04-Nov-2019 08:03:14

110 Views

Suppose we have the center coordinate and one coordinate point on the perimeter of the circle. We have to find the another point on the perimeter. Consider the center points are (p, q), and one given point is (a, b). We have to find the point (x, y). As we know that the center is the middle point of the diameter. So we can write them like −(p, q)=(a+x/2, b+y/2)Or from this the (x, y) can be expressed as −x=2p-a, y=2q-bExample#include using namespace std; int getCylinderPerimeter(int d, int h) {    return (2*d) + (2*h); } int main() {   ... Read More

Find Number Containing Digit D in C++

Arnab Chakraborty
Updated on 04-Nov-2019 08:01:20

195 Views

Consider we have a digit d, and the upper limit n. we have to find all numbers that contains d in range 0 to n. So if n = 20, and digit is 3, then the numbers will be [3, 13].To solve this problem, we will take every number as string, then if the digit is present in the string, the number will be printed, otherwise ignored.Example#include using namespace std; int getAllNumWithDigit(int n, int d) {    string str = "";    str += to_string(d);    char ch = str[0];    string p = "";    p += ch;    for (int i = 0; i

Dictionary ContainsValue Method in C#

AmitDiwan
Updated on 04-Nov-2019 07:59:08

4K+ Views

The Dictionary.ContainsValue() method in C# is used to check whether the Dictionary contains a specific value or not.Syntaxpublic bool ContainsValue (TValue val);Above, Val is the value to be searched.Let us now see an example to implement the Dictionary.ContainsValue() method −Exampleusing System; using System.Collections.Generic; public class Demo {    public static void Main(){       Dictionary dict =       new Dictionary();       dict.Add("One", "John");       dict.Add("Two", "Tom");       dict.Add("Three", "Jacob");       dict.Add("Four", "Kevin");       dict.Add("Five", "Nathan");       Console.WriteLine("Count of elements = "+dict.Count);       Console.WriteLine("Key/value ... Read More

Find Next Perfect Square Greater Than a Given Number in C++

Arnab Chakraborty
Updated on 04-Nov-2019 07:55:45

552 Views

Suppose we have a number n. our task is to find next perfect square number of n. So if the number n = 1000, then the next perfect square number is 1024 = 322.To solve this, we have get the square root of the given number n, then take the floor of it, after that display the square of the (floor value + 1)Example#include #include using namespace std; int justGreaterPerfectSq(int n) {    int sq_root = sqrt(n);    return (sq_root + 1)*(sq_root + 1);    } int main() {    int n = 1000;    cout

Find Length of Each String Element in Numpy Array using C++

Arnab Chakraborty
Updated on 04-Nov-2019 07:52:59

173 Views

Here we will see how to get the length of each string element in the Numpy Array. Numpy is a library for Numeric Python, and it has very powerful array class. Using this we can store data in an array like structure. To get the length we can follow two different approach, these are like below −Exampleimport numpy as np str_arr = np.array(['Hello', 'Computer', 'Mobile', 'Language', 'Programming', 'Python']) print('The array is like: ', str_arr) len_check = np.vectorize(len) len_arr = len_check(str_arr) print('Respective lengts: ', len_arr)OutputThe array is like: ['Hello' 'Computer' 'Mobile' 'Language' 'Programming' 'Python'] Respective lengts: [ 5 8 6 8 ... Read More

Dictionary ContainsKey Method in C#

AmitDiwan
Updated on 04-Nov-2019 07:49:19

2K+ Views

The Dictionary.ContainsKey() method in C# checks whether the Dictionary

Find Sum of Factorials in an Array in C++

Arnab Chakraborty
Updated on 04-Nov-2019 07:43:09

270 Views

Consider we have an array A, which is sorted. It has all elements appears twice, but one element is present for only one time. We have to find that element. If the array is [1, 1, 3, 3, 4, 4, 5, 6, 6, 7, 7, 9, 9], so the single element is 5.We will use the binary search approach to solve this. All elements before the single element has their first occurrence at index 0, 2, 4, … and first occurrence at index 1, 3, 5, … but after the single element, all occurrences of the first number will be ... Read More

Find Largest Word in Dictionary by Deleting Characters in C++

Samual Sam
Updated on 01-Nov-2019 10:54:54

244 Views

Consider we have a dictionary, and a string s. Find the longest string in the dictionary, that can be formed by deleting some characters of the string s. Suppose the s is “apbreoigroakml”, The dictionary has {“prog”, “ram”, “program”}, then the result will be “program”.To solve this, we will traverse all dictionary words, and for each word, we will check whether the subsequence of the given string and is longest of all such words. Finally return longest word with given string as subsequence.Example#include #include using namespace std; bool isSubSequence(string s1, string s2) {    int m = s1.length(), n = ... Read More

Advertisements