Server Side Programming Articles - Page 1649 of 2650

Program to compare two fractions in C

Sunidhi Bansal
Updated on 13-Aug-2020 08:15:19

734 Views

Given two fractions with some numerator nume1 and nume2 and deno1 and deno2 as their respective denominator, the task is to compare both the fractions and find out the greater one. Like we have a fraction 1/2 and 2/3 and the higher one is 2/3 because the value of 1/2 is 0.5 and the value of 2/3 is 0.66667 which is higher.Input first.nume = 2, first.deno = 3 second.nume = 4, second.deno = 3Output 4/3Explanation 2/3 = 0.66667 < 4/3 = 1.33333Input first.nume = 1, first.deno = 2 second.nume = 4, second.deno = 3Output 4/3Approach used below is as follows to solve the problem//baadme likhungaAlgorithmStart ... Read More

Program to check if an array is sorted or not (Iterative and Recursive) in C

Sunidhi Bansal
Updated on 13-Aug-2020 08:13:30

4K+ Views

Given an array arr[] with n number of elements, our task is to check whether the given array is in sorted order or not, If it is in sorted order then print “The array is in sorted order”, else print “The array is not in sorted order”.To solve the above stated problem we can use Iterative or Recursive approach, we will be discussing both.Recursive ApproachSo, what is a Recursive approach? In Recursive approach we recursively call a function again and again until we get the desirable result. In recursive approach the values returned by function is stored in stack memory.Input arr[] ... Read More

Program to check if a string contains any special character in C

Sunidhi Bansal
Updated on 13-Aug-2020 08:10:20

7K+ Views

Given a string str[], the task is to check whether the string contains any special character and if the string have a special character then print “The String is not accepted” else print “The string is accepted”.Special characters are those characters which are neither numeric nor alphabetic i.e. − !@#$%^&*()+=-\][‘;/., {}|:”?`~So in C Programming language we will use if-else approach to solve the problem.Input − str[] = {“tutorials-point”}Output − the string is not acceptedInput − str[] = {“tutorialspoint”}Output − The string is acceptedApproach used below is as follows to solve the problem −Traverse the whole string.Will look for the special ... Read More

Product of N with its largest odd digit in C

Sunidhi Bansal
Updated on 13-Aug-2020 08:07:52

439 Views

Given a number N with we have to product the number with its largest odd digit. If there is no odd digit then print -1.Like we have initialized N with “153” and the largest odd digit in this number is 5 so the result would be the product of 153 with 5 i.e. 153 * 5 = 765 and if the number has no odd digit like 246 then the output must be -1.Input − N = 198Output − 1782Explanation − 198 * 9 = 1782Input − N = 15382Output − 76910Explanation − 15382 * 5 = 76910Approach used below ... Read More

Product of maximum in first array and minimum in second in C

Sunidhi Bansal
Updated on 13-Aug-2020 08:05:26

325 Views

Given two arrays arr1[] and arr2[] of some size n1 and n2 respectively, we have to find the product of maximum element of first array arr1[] and minimum element of the second array arr2[].Like we have elements in arr1[] = {5, 1, 6, 8, 9} and in arr2[] = {2, 9, 8, 5, 3} so the maximum element in arr1 is 9 and the minimum element in arr2 is 2 so the product of both is 9*2 = 18, likewise we have to write a program to solve the given problem.Input arr1[] = {6, 2, 5, 4, 1} arr2[] = {3, ... Read More

Product of factors of number in C++

Sunidhi Bansal
Updated on 13-Aug-2020 08:02:58

455 Views

Given a number n we have to find its all factors and find the product of those factors and return the result, i.e, the product of factors of a number. Factors of a number are those numbers which can divide the number completely including 1. Like factors of 6 are − 1, 2, 3, 6.Now according to the task we have to find the product all the factors of the number.Input − n = 18Output − 5832Explanation − 1 * 2 * 3 * 6 * 9 * 18 = 5832Input − n = 9Output − 27Explanation − 1 * 3 * 9 = 27Approach used below is as follows to solve the problem −Take the input num .Loop from i = 1 till i*i

Product of first N factorials in C++

Sunidhi Bansal
Updated on 13-Aug-2020 07:59:24

387 Views

Given a number N, the task is to find the product of first N factorials modulo by 1000000007. . Factorial implies when we find the product of all the numbers below that number including that number and is denoted by ! (Exclamation sign), For example − 4! = 4x3x2x1 = 24.So, we have to find a product of n factorials and modulo by 1000000007..Constraint 1 ≤ N ≤ 1e6.Input n = 9Output 27Explanation 1! * 2! * 3! * 4! * 5! * 6! * 7! * 8! * 9! Mod (1e9 + 7) = 27Input n = 3Output 12Explanation 1! * 2! * 3! mod (1e9 ... Read More

Printing string in plus ‘+’ pattern in the matrix in C++

Sunidhi Bansal
Updated on 13-Aug-2020 07:58:02

268 Views

Given a string str, we have to print the given string str in ‘+’ pattern in the matrix. To form plus pattern in a matrix the matrix must be a square matrix. A square matrix is that matrix which has same number of rows and column.Like we have a string “Tutor” our task is to print the string horizontally and vertically intersecting each other from the center, and make the rest of the elements of the matrix as “x” like in the given figure −Input str[] = {“Point”}Output Input str[] = {“this”}Output Pattern not possibleApproach used below is as follows to solve the problemGet ... Read More

Program for centered nonagonal number in C++

Sunidhi Bansal
Updated on 13-Aug-2020 07:45:04

98 Views

Given with a value ‘n’ and the task is to generate the centered nonagonal number for n and centered nonagonal series till n and display the results.What is centered nonagonal number?Centered nonagonal number contains the nonagonal layers formed by the dots and one corresponding dot in the center.Given above is the figure of centered nonagonal number 𝑁2.It can be calculated using the formula −$$Nc(n)=\frac{(3n-2)(3n-1)}{2}$$Input number: 20Output centered nonagonal number : 1711Input number: 10Output centered nonagonal series : 1 10 28 55 91 136 190 253 325 406AlgorithmStart Step 1→ declare function to calculate centered nonagonal number    int calculate_number(int num)       return ... Read More

Program for Centered Icosahedral Number in C++

Sunidhi Bansal
Updated on 13-Aug-2020 07:42:50

151 Views

Given with a value ‘n’ and the task is to generate the centered Icosahedral number for n and centered Icosahedral series till n and display the results.What is centered Icosahedral number?Centered Icosahedral number is a centered number used for representing an icosahedrons(it is a polyhedron figure with 20 faces).The first few centered icosahedral number series till n = 1000 are −1, 13, 55, 147, 309, 561, 923Centered Icosahedral number can be calculated using the formula −$$(2n+1)\times\frac{5n^{2}+5n+3}{3}$$Input number: 20Output Centered Icosahedral Number is : 28741Input number: 12Output Centered Icosahedral Number is : 6525AlgorithmStart Step 1→ declare function to calculate centered iscosahedral number    int calculate(int ... Read More

Advertisements