In this problem, we are given an integer N. The task is to find n-th term in series 9, 33, 73, 129....Let’s take an example to understand the problem, InputN = 4Output129ExplanationThe series upto nth term is 9, 33, 73, 129...Solution ApproachThe solution to the problem lies in finding the nth term of the series. We will find it mathematically and then apply the general term formula to our program.First let’s subtract the series by shifting it by one.Sum = 9 + 33 + 73 + … + t(n-1) + t(n) - Sum = 9 + 33 + 73 + ... Read More
In this problem, we are given an integer N. The task is to find n-th term in series 7, 15, 32....Let’s take an example to understand the problem, InputN = 6Output281ExplanationThe series upto nth term is 7, 15, 32, 67, 138, 281Solution ApproachThe solution to the problem lies in decoding the series. You can see the series is a mix of series.The subtracting the values, T(2) - T(1) = 15 - 7 = 8 T(3) - T(2) = 32 - 15 = 17 So, T(2) = 2*T(1) + 1 T(3) = 2*T(2) + 2 T(n) = 2*T(n-1) + ... Read More
In this problem, we are given an integer N. The task is to find n-th term in series 1 2 2 3 3 3 4….Let’s take an example to understand the problem, InputN = 6Output3ExplanationThe series upto nth term is 1, 2, 2, 3, 3, 3, ...Solution ApproachA simple approach to solve the problem is by using a nested loop. The outer for loop is from 1 to n. And the inner loop is from 1 to i (iterator of outer loop). For each iteration in the inner loop, count the number of elements of the series and return the ... Read More
In this problem, we are given a binary tree and an integer N. The task is to find the n-th node in inorder traversal of a Binary Tree.A binary tree has a special condition that each node can have a maximum of two children.Traversal is a process to visit all the nodes of a tree and may print their values too.Let’s take an example to understand the problem, InputN = 6Output3Explanationinorder traversal of tree : 4, 2, 5, 1, 6, 3, 7Solution ApproachThe idea is to use the in-order traversal of the binary tree which is done by using recursive ... Read More
In this problem, we are given a binary tree and an integer N. The task is to find the n-th node in Preorder traversal of a Binary Tree.A binary tree has a special condition that each node can have a maximum of two children.Traversal is a process to visit all the nodes of a tree and may print their values too.Let’s take an example to understand the problem, InputN = 6Output6ExplanationPre order traversal of tree : 1, 2, 4, 5, 3, 6, 7Solution ApproachThe idea is to use the pre-order traversal of the binary tree which is done by using ... Read More
CSS object-fit and object-position property helps us crop images and specify how it is displayed in an element.The syntax of CSS object-fit property is as follows −Selector { object-fit: /*value*/ object-position:/*value*/ }ExampleThe following examples illustrate CSS object-fit property. Live Demo img { object-fit: cover; } img:last-of-type { object-fit: contain; } cover contain OutputThis will produce the following result −Example Live Demo div { border: 1px solid blue; width:100%; height:300px; } img { float:left; width:50%; height:100%; object-fit:cover; object-position: 20px -10px; } OutputThis will produce the following result −Effect of resizing
In this program, we are trying to check whether the two given numbers by the user through console, are friendly pair or not?ExampleIf sum of all divisors of number1 is equal to number1 and sum of all divisors of number2 is equal to number2, then we can say, those two numbers are abundant numbers.The logic that we used to find friendly pairs is as follows −For the sum of all divisors of number 1.for(i=1;i
Squeeze(s1, s2) or squeeze(char[], char[]) is a user defined function which is used to delete the common characters or equal characters in two strings.ProblemHow to delete the common characters in two strings using squeeze function in C programming language?SolutionIn this program, the user enters two strings in the console and write a code to display first string excluding the common characters present in second string.ExampleThe C program which demonstrates the functioning of squeeze function is as follows − Live Demo#include void squeeze(char string1[], char string2[]);//prototype declaration int main(){ char string1[50]; char string2[30]; printf("enter the string1:"); scanf("%s", string1);// ... Read More
The different data types that we use in C programming are integer, short int, Signed and un signed char etc.Data TypesData type specifies the set of values and the type of data that can be stored in a variable. They allow the programmer to select the type appropriate to the needs of application.The data types are as follows −Primary data typesDerived data typesLet us understand primary data types.Primary data types‘C’ compilers support four fundamental data types. They are mentioned below −integercharacterFloating – pointDouble precision floating pointIntegral data typeIntegral data types are used to store whole numbers and characters. It is ... Read More
Arrays are a kind of data structure that can store a fixed-size sequential collection of elements of the same type.An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type.LimitationsThe limitations of an array are explained below −An array which is formed will be homogeneous. That is, in an integer array only integer values can be stored, while in a float array only floating value and character array can have only characters. Thus, no array can have values of two data ... Read More