Server Side Programming Articles - Page 2152 of 2650

C Program to check if matrix is singular or not

Sunidhi Bansal
Updated on 18-Oct-2019 13:15:52

1K+ Views

Given a matrix as mat[row][column], our task is to check whether the given matrix is singular or not through a function and display the result.Singular matrix is a matrix whose determinant is zero and if the determinant is not zero then the matrix is non-singular.So to find whether the matrix is singular or non-singular we need to calculate determinant first. Determinant of a matrix can be calculated as −$$M1[3][3]\:=\:\begin{bmatrix}a & b & c \d & e & f \g & h & i \end{bmatrix}$$|m1| = a(e*i - f*h) - b(d*i - f*g) + c(d*h - e*g)ExampleInput-: mat[3][3]= { 4, 10, ... Read More

Program to compute Log n in C

Sunidhi Bansal
Updated on 18-Oct-2019 13:05:04

539 Views

Given with the value of n as an input and the task is to compute the value of Log n through a function and display it.Logarithm or Log is the inverse function to exponentiation which means to calculate log the raised power must be calculated as a base.IF  $$\log_b x\;\:=\: y\:than\:b^{y}=x$$Like $$\log_2 64\;\:=\: 6\:than\:2^{6}=64$$ExampleInput-: Log 20 Output-: 4 Input-: Log 64 Output-: 6AlgorithmStart In function unsigned int log2n(unsigned int num)    Step 1-> Return (num > 1) ? 1 + log2n(num / 2) : 0 In function int main()    Step 1-> Declare and assign num = 20    Print log2n(num) ... Read More

Products of ranges in an array in C

Sunidhi Bansal
Updated on 18-Oct-2019 12:57:04

625 Views

Given with array, L, R, P as an input and the task is to find the ranges between L and R with the product under modulo as output and display itAs given in the figure we have array of elements and L which is a Left value as 2 and R which is the Right value as 2. Now the program must find the products of ranges between them.ExampleInput-:  A[] = { 1, 2, 3, 4, 5, 6 }    P = 29  L = 2 R = 6 Output-: 24 Input-: A[] = {1, 2, 3, 4, 5, 6},   ... Read More

C Program for diamond pattern with different layers

Sunidhi Bansal
Updated on 18-Oct-2019 12:40:05

307 Views

Given with the number and the task is to generate the diamond pattern with the given n different layers and display it.ExampleInput: n = 3Output:Approach used in the below program is as follows −Input the number of rowsAnd in this pattern there are ((2 * n) + 1) rowsNumber of spaces from 0 – n is (2 * (n – i))And the number of spaces from n+1 till end are ((i – n) * 2)AlgorithmStart Step 1-> declare a function to print a pattern    void print_pattern(int n)    declare variables as int i, j    Loop For i = 1 i

C Program to add two fractions

Sunidhi Bansal
Updated on 18-Oct-2019 12:26:44

3K+ Views

Given with the input as fraction i.e. a/b and c/d where a, b, c and d can be any integer values other than 0 and the task is to add these two fraction to generate their final sum.Fractions are represented by −a / b, where a is known as numerator and b is known as denominator.a and b can have any numeric values but b can have any numeric value other than 0.Sum of two fractions is represented as a / b + c / d, and the rule for adding the two terms is that their denominator must be ... Read More

C++ Program for sum of arithmetic series

Sunidhi Bansal
Updated on 18-Oct-2019 12:18:02

4K+ Views

Given with ‘a’(first term), ‘d’(common difference) and ‘n’ (number of values in a string) and the task is to generate the series and thereby calculating their sum.What is an Arithmetic seriesArithmetic series is the sequence of numbers with common difference where the first term of a series is fixed which is ‘a’ and the common difference between them is ‘d’.It is represented as −a, a + d, a + 2d, a + 3d, . . .ExampleInput-: a = 1.5, d = 0.5, n=10 Output-: sum of series A.P is : 37.5 Input : a = 2.5, d = 1.5, n ... Read More

C++ Program to check if tank will overflow, underflow or filled in given time

Sunidhi Bansal
Updated on 18-Oct-2019 12:07:06

292 Views

Given with the rate of filling the tank, height of a tank and radius of a tank and the task is to check whether the tank is overflow, underflow and filled in given time.ExampleInput-: radius = 2, height = 5, rate = 10 Output-: tank overflow Input-: radius = 5, height = 10, rate = 10 Output-: tank undeflowApproach used below is as follows −Input the rate of filling time, height and radius of a tankCalculate the volume of a tank to find the original rate of flow of water.Check for the conditions to determine the resultIf expected < original ... Read More

C++ Program to check if input is an integer or a string

Sunidhi Bansal
Updated on 02-Nov-2023 13:08:18

43K+ Views

Given with an input by the user and the task is to check whether the given input is an integer or a string. Integer can be any combination of digits between 0 -9 and string can be any combination excluding 0 – 9. Example Input-: 123 Output-: 123 is an integer Input-: Tutorials Point Output-: Tutorials Point is a string Approach used below is as follows − Input the data. Apply isdigit() function that checks whether a given input is numeric character or not. This function takes single argument as an integer and also returns ... Read More

C++ program to check if first and the last characters of string are equal

Sunidhi Bansal
Updated on 18-Oct-2019 11:27:44

1K+ Views

Given with an input of string and the task is to check whether the first and last characters of given string is equal or not.ExampleInput-: study Output-: not equal    As the starting character is ‘s’ and the end character of a string is ‘y’ Input-: nitin Output-: yes it have first and last equal characters    As the starting character is ‘n’ and the end character of a string is ‘n’Approach used below is as follows −Input the string and store in an array of strings.Calculate the length of a string using length() functionCheck first and last element of ... Read More

C++ program to Calculate the Edge Cover of a Graph

Sunidhi Bansal
Updated on 18-Oct-2019 11:22:39

265 Views

Given a n number of vertices of a graph, the task is to calculate the edge cover of the graph. Edge cover is to find the minimum number of edges required to cover every vertex of the graph.Like we have n = 5Then its graph will be like −So its edge cover is 3Let’s take another example where the n is 8And its edge cover will be:4ExampleInput: n= 5 Output: 3 Input: n= 8 Output: 4Approach used below is as follows −Take the input from the userFind the ceiling value of the result of number of vertices by dividing it ... Read More

Advertisements