Found 1339 Articles for C

Profit and loss Problems using C

Sunidhi Bansal
Updated on 13-Aug-2020 08:29:46

3K+ Views

Given a certain cost price(cp) and a selling price(sp) of an unknown product or a service, our task is to find the profit earned or loss suffered using a C program where if the profit is earned should print “Profit” and it’s amount or if the loss is suffered “Loss” and its respective amount or if there is not profit no loss then print “No profit nor Loss”.To find the profit or the loss we generally see whether the selling price(sp) or the price/amount at which a certain thing is sold or the cost price(cp) at which a certain thing ... Read More

Product of given N fractions in reduced form in C

Sunidhi Bansal
Updated on 13-Aug-2020 08:24:17

221 Views

Given the numerator num and denominator den of N fractions, the task is to find the product N fractions and output should be in reduced form.Like in the given figure below we have two fractions ”4/5” and “3/4” we have found the product of those two factions where the numerator of first is multiplied by the numerator of second and the denominator of the first is multiplying the denominator of the second. Now the final result is “12/20” which can be reduced so the output shall be “3/5 ” likewise we have to develop a program to solve the given ... Read More

Program to 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

Program to compare two fractions in C

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

712 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

429 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

310 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

Bitwise recursive addition of two integers in C

sudhir sharma
Updated on 05-Aug-2020 08:00:49

4K+ Views

In this problem, we are given two numbers. Our task is to create a C program for the Bitwise recursive addition of two integers.The logic to find the sum using the Bitwise operations is similar to what we used to do when we were in preschool. For finding the sum, we used to add each digit of the number and if a carry is there, we add it to the next digit.We will do a similar thing, find the sum using the XOR operator and check for the carry using the AND operation. If there is a carry we will ... Read More

Advertisements