Programming Articles - Page 2489 of 3366

C Program for Print the pattern by using one loop

Sunidhi Bansal
Updated on 08-Aug-2019 09:27:32

4K+ Views

The challenge is to display the pattern using one loop only and with continue statement.AlgorithSTART Step 1 -> declare start variables i and j to 0 with number of rows in n to 6 Step 2 -> Loop For i=1 and i

Print triplets with sum less than or equal to k in C Program

Sunidhi Bansal
Updated on 01-Jul-2020 08:08:03

176 Views

Given array with set of elements and the task is to find out set with exactly three elements having sum less than or equals to k.Input − arr[]= {1, 2, 3, 8, 5, 4}Output − set → {1, 2, 3} {1, 2, 5} {1, 2, 4} {1, 3, 5} {1, 3, 4} {1, 5, 4} {2, 3, 5} {2, 3, 4}In this, first task is to calculate the size of array depending upon which for loop of i is iterated till size-2 and for loop of j is iterated till size-1 and for loop of k is iterated till sizeAlgorithSTART Step 1 ... Read More

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

236 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

352 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

203 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

Importance of deepToString() and asList() methods in Java?

Vivek Verma
Updated on 29-May-2025 17:38:52

416 Views

In Java, both deepToString() and asList() methods are static methods of the Arrays class. An array is an object that holds a fixed number of values of a similar type in a contiguous memory location. The deepToString() Method In Java, the deepToString() method is used to convert a multi-dimensional array into a string. It checks if any element in the array is also an array; it will convert that inner array to a string as well. Syntax Following is the syntax of the Arrays.deepToString() method: public static String deepToString(Object[] a) Here, a: An array ... 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

175 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

Advertisements