Server Side Programming Articles - Page 2208 of 2646

Print longest palindrome word in a sentence in C Program

Sunidhi Bansal
Updated on 08-Aug-2019 09:12:57

1K+ Views

Given a sentence and the challenge is to find the longest palindrome from the given sentenceWhat is a Palindrome?Palindrome is a word or sequence whose meaning remains same even after reversing the stringExample − Nitin, after reversing the string its meaning remains the same.Challenge is to find the longest palindrome from the given sentence.Like sentence is: malayalam liemadameil ijiIt contains three palindrome words but the longest is − liemadameilAlgorithmSTART STEP 1 -> Declare start variables I, j, k, l, max to 0, index to -1, check to 0, count to 0 Step 2 -> Loop For i to 0 and ... Read More

Print n 0s and m 1s such that no two 0s and no three 1s are together in C Program

Sunidhi Bansal
Updated on 08-Aug-2019 09:08:00

255 Views

There should be sequence of N 0’s and M 1’s such that the sequence so formed shouldn’t contain two consecutive 0’s with three consecutive 1’s.Input − N=5 M=9Output − 1 1 0 1 1 0 1 1 0 1 0 1 0 1Note − To make the above sequence, the statement (m < n-1) || m >= 2 * (n + 1) should be false if it is true than we can’t make the above sequence.It is advisable to first go through question logic and try yourself instead of jumping to the solution directly given below.AlgorithmSTART Step 1 -> take values in ... Read More

C Program for Print individual digits as words without using if or switch.

Sunidhi Bansal
Updated on 08-Aug-2019 09:02:44

376 Views

Print the given numeric value as words. It’s easy to do with switch using cases from 0-9 but challenge is without using them.Input  − N=900Output − NINE ZERO ZEROIt is possible by creating array of pointers that contains 0-9 in words.AlgorithmSTART Step 1 -> declare int variables num, i and array of pointer char *alpha with values {"ZERO", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE"} Step 2 -> declare char array str[20] Step 3 -> call function itoa with parameters num, str, 10 Step 4 -> Loop For i=0 and str[i]!=’\o’ and i++    Print alpha[str[i] - '0'] ... Read More

Print first k digits of 1/n where n is a positive integer in C Program

Sunidhi Bansal
Updated on 08-Aug-2019 08:59:15

218 Views

Input number N such that 1/N will return the output generated as decimal specified till the limit.It is easy with Floating Point numbers but the challenge is without using them.Input − n=5 k=5Output − 20000It means if n=5 and k=5 than after dividing 1/5 the output should be displayed till 5 decimal points.AlgorithmStart Step 1 -> Declare int variable n to 9 and k to 7 and remain to 1 and i Step 2-> Loop for i to 0 and i end Loop For StopExample#include int main() {    int n = 9, k = 7, remain=1, i ; // taking n ... Read More

Print multiples of Unit Digit of Given Number in C Program

Sunidhi Bansal
Updated on 08-Aug-2019 08:50:18

5K+ Views

Input number N and fetch the unit digit of a given number and display the multiples of that number.Input − N=326Output − unit digit is 6 and its multiples are 2 and 3Note − Unit digit of any number can be fetched by calculating the %10 with that numberFor example − if your’re given with a number N and you need to find its unit digit thatyou can use N%10 it will return you unit digit of number NALGORITHMSTART Step 1 -> Declare start variables num, num2 and i Step 2 -> input number num Step 3 -> store num%10 in num2 ... Read More

Area of a square inscribed in a circle which is inscribed in an equilateral triangle in C Program?

sudhir sharma
Updated on 13-Aug-2019 10:21:35

187 Views

The program to find the area of a square inscribed in a circle which itself is inscribed in an equilateral triangle. The radius of circle inscribed inside an equilateral is a/(2√3).The diameter of circle is the diagonal of square, d = 2 * r = a/ √3 Area formula for area of square given its diagonals is ½ d2, A = 0.5 * d2 A = (1/2) * (a2) / (3) = (a2/6) Example#include using namespace std; int main() {    float area,a = 10;    area = (a*a) / 6;    cout

C++ Program string class and its applications?

sudhir sharma
Updated on 08-Aug-2019 08:18:41

172 Views

String is a sequence of characters. In C++ programming language, The strings can be defined in two ways −C style strings: treats the string as a character array.String Class in C++The string class can be used in a C++ program from the library ‘string’. It stores the string as a character array in the memory but shows it as a string object to the user. In C++ there are many methods that support the C++ string class and help in the proper function of the object and increase the efficiency of the code.ExampleSome common string application are found where string ... Read More

C vs BASH Fork bomb?

sudhir sharma
Updated on 08-Aug-2019 08:09:29

333 Views

Fork() bomb is a Dos (Denial Of Service) attack against the linux based system. This calls the Fork() system infinite number of times that fills the memory of the program and intends to harm the system.Bash script for fork bomb:(){ :|: & };:The code explained as :( ) is function definition, { } defines the body of the loop. :|:& create a memory location and does not allow it to get deallocated. This program call itself multiple number of time again and again. Thus calling infinite calls.C Fork bomb is also the same type of Dos but it can be ... Read More

C/C++ Programming to Count trailing zeroes in factorial of a number?

sudhir sharma
Updated on 08-Aug-2019 08:06:48

887 Views

Counting the number of trailing zeroes in a factorial number is done by counting the number of 2s and 5s in the factors of the number. Because 2*5 gives 10 which is a trailing 0 in the factorial of a number.ExampleFactorial of 7 = 5040, the number of trailing 0’s is 1.Based on our logic 7! = 2*3*4*5*6*7, it has 3 2s and 1 5s so the number of trailing 0’s is 1.#include using namespace std; int main() {    int n = 45;    int count = 0;    for (int i = 5; n / i >= 1; i *= 5)       count += n / i;    cout

Sum of squares of first n natural numbers in C Program?

sudhir sharma
Updated on 08-Aug-2019 08:01:53

14K+ Views

The sum of squares of the first n natural numbers is found by adding up all the squares.Input - 5Output - 55Explanation - 12 + 22 + 32 + 42 + 52There are two methods to find the Sum of squares of first n natural numbers −Using Loops − the code loops through the digits until n and find their square, then add this to a sum variable that outputs the sum.Example#include using namespace std; int main() {    int n = 5;    int sum = 0;    for (int i = 1; i >= n; i++)       sum += (i * i);    cout

Advertisements