Add Two Complex Numbers in C

Sunidhi Bansal
Updated on 13-Aug-2020 08:21:01

10K+ Views

Given are the two complex numbers in the form of a1+ ib1 and a2 + ib2, the task is to add these two complex numbers.Complex numbers are those numbers which can be expressed in the form of “a+ib” where “a” and “b” are the real numbers and i is the imaginary number which is the solution of the expression 𝑥 2 = −1 as no real number satisfies the equation that’s why it is called as imaginary number.Input a1 = 3, b1 = 8 a2 = 5, b2 = 2Output Complex number 1: 3 + i8 Complex number 2: 5 + i2 ... Read More

Product of Middle Row and Column in an Odd Square Matrix in C

Sunidhi Bansal
Updated on 13-Aug-2020 08:18:56

249 Views

Given a square matrix, mat[row][column] where row and column are equal and are of odd length means the number of row and column must me odd, i.e, not divisible by 2, the task is to find the product of middle row and middle column of that matrix.Like in the given figure below −ConstraintsMatrix must be a square matrix.Column and rows must be of odd length.Input mat[][] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}Output Product of middle row = 120 Product of middle column = 80Explanation Product of middle row = 4 * 5 * 6 = 120 Product of middle ... Read More

Compare Two Fractions in C

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

713 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

Check if an Array is Sorted or Not in C - Iterative and Recursive Methods

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

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

431 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

311 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 a Number in C++

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

443 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

377 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-Plus Pattern in C++

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

254 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

Advertisements