Check If a Given String Is a Palindrome in C

sudhir sharma
Updated on 09-Aug-2019 12:29:30

10K+ Views

A palindrome is a word, number, phrase, or other sequences of characters which reads the same backward as forward. Words such as madam or racecar or the number 10801 are a palindrome.For a given string if reversing the string gives the same string then we can say that the given string is a palindrome. Which means to check for the palindrome, we need to find whether the first and last, second and last-1, and so on elements are equal or not.Input − naman Output − string is a palindrome Input − tutorials point Output − string is not a palindromeIn C++ Program to ... Read More

Concatenate a String Given Number of Times in C++ Programming

sudhir sharma
Updated on 09-Aug-2019 12:24:08

806 Views

A program to concatenate a string a given number of times will run the string concatenate method n number of times based on the value of n.The result would be string repeated a number of times.Examplegiven string: “ I love Tutorials point” n = 5OutputI love Tutorials pointI love Tutorials pointI love Tutorials pointI love Tutorials point I love Tutorials pointAfter seeing the output, it is clear that what the function will do.Example#include #include using namespace std; string repeat(string s, int n) {    string s1 = s;    for (int i=1; i

bitset All Function in C++ STL

sudhir sharma
Updated on 09-Aug-2019 12:21:03

185 Views

The bitset all() function an inbuilt function of the C++ STL( Standard Template Library). This function returns a Boolean value. The returned value is true if all the bits of the calling bitset are 1 else it will return false.The function does not accept any parameter and returns a Boolean value.SyntaxBool bitset_name .all()SampleBitset = 100101OutputfalseBecause all bits of the set need to be true in order to return a true value.Example#include using namespace std; void printer(bool val){    if(val){       cout

Bitset Flip in C++ STL

sudhir sharma
Updated on 09-Aug-2019 12:18:27

597 Views

The bitset flip() method is an inbuilt method of C++ STL( Standard Template Library). It flips the bits of the calling bitset. This method flips all 0’s to 1’s and all 1’s to 0’s, which means it reverse each and every bit of the calling bitset when no parameter is passed.If a parameter is passed the flip method will flip only the nth bit for the integer n passed. For example, if 5 is passed then the flip method will flip 5th bit of of the calling bitset.Syntaxbitset_name.flip(int pos)SampleInitial bitset: 011001After applying the bits flip function with no parameter: 100110After ... Read More

Delete a Tree in C Programming

sudhir sharma
Updated on 09-Aug-2019 12:11:42

1K+ Views

To delete a tree we need to traverse each node of the tree and then delete each of them. this one by one delete every node of the tree and makes it empty. For this, we need to use a method that traverses the tree from bottom to up so that we can delete the lower notes first and then their parents so that no extra complexities arise. Based on the condition that we need, The postorder traversal will be the best suited And works efficiently so that our program will be optimum.The post-order for the following tree is -2-6-4-12-17-15The ... Read More

Function that Returns 2 for Input 1 and 1 for Input 2 in C Programming

sudhir sharma
Updated on 09-Aug-2019 12:08:13

411 Views

A function that returns 2 for input 1 and 1 for input 2 is to be made. This function can be made in many ways based on the logic you use. The easiest way to do this is to use a conditional statement that if the number is 1 then return 2 otherwise return 1 and ways include using mathematical operations (any will do) and XOR operation.Example#include // Method 1 using the if statement int reverseif(int x) {    if (x == 1) return 2;    else return 1; } // Method 2 using the subtarction form sum of ... Read More

Ways to Paint N Paintings without Adjacent Colors in C Programming

sudhir sharma
Updated on 09-Aug-2019 12:04:02

691 Views

In this problem, you are given N painting and we have m color that we can make paintings with and we need to find the number of ways in which we can draw the painting such that none of the same color paintings are to each other.The program’s output can have very large values and handing these values is a bit problem so we will calculate its answer in standard modulo 109 +7.The formula to find the number ways is :Ways = n*(m-1)(n-1)Example to describe the problem, this will need the number of paintings n and number of colors m ... Read More

Surface Area and Volume of Hexagonal Prism in C Programming

sudhir sharma
Updated on 09-Aug-2019 12:01:50

494 Views

The surface area of any figure is the total area that it's surface cover.A hexagonal prism is a three-dimensional figure that has a hexagon at both its ends. exam on prism looks like -In mathematics, Hexagonal prism is defined as three dimensional figure with 8 faces, 18 edges, 12 vertices.Surface Area = 3ah + 3√3*(a2) Volume = (3√3/2)a2hExample#include #include int main() {    float a = 5, h = 10;    //Logic to find the area of hexagonal prism    float Area;    Area = 6 * a * h + 3 * sqrt(3) * a * a;   ... Read More

Sums of ASCII Values of Each Word in a Sentence in C Programming

sudhir sharma
Updated on 09-Aug-2019 11:49:06

434 Views

The ASCII value of the ward is the integer presentation based on ASCII standards. In this problem, we are given a sentence and we have to calculate the sum of ASCII values of each word in the sentence.For this we will have to find the ASCII values of all the characters of the sentence and then add them up, this will give the sum of ASCII values of letters in this word. we have to do the same for all words and finally, we will add all the sums and give a final sum of ASCII values of each word ... Read More

Sum Triangle from an Array in C Programming

sudhir sharma
Updated on 09-Aug-2019 11:46:46

740 Views

The sum triangle from an array is a triangle that is made by decreasing the number of elements of the array one by one and the new array that is formed is with integers that are the sum of adjacent integers of the existing array. This procedure continues until only one element remains in the array.Let's take an example to explain the content better, Array = [3, 5, 7, 8, 9]Output[106] [47, 59] [20, 27, 32] [8, 12, 15, 17] [3, 5, 7, 8, 9]ExplanationFor the first array : ( 3 + 5 = 8), ( 5 + 7 = ... Read More

Advertisements