Find Roots of Quadratic Equation in C

Ayush Gupta
Updated on 09-Jul-2020 08:55:12

3K+ Views

In this tutorial, we will be discussing a program to find the roots of the Quadratic equation.Given a quadratic equation of the form ax2 + bx + c. Our task is to find the roots x1 and x2 of the given equation.For this, we are using the deterministic method, in thisD = √b2 - 4acthen the roots of the equation will bex1 = (-b + D)/2a ,andx2 = (-b - D)/2aExample#include #include #include //calculating the roots of equation void calc_roots(int a, int b, int c) {    if (a == 0) {       printf("Invalid Equation");       ... Read More

Find the Side of the Octagon Inscribed Within a Square in C++

Ayush Gupta
Updated on 09-Jul-2020 08:54:48

121 Views

In this tutorial, we will be discussing a program to find the side of the octagon inscribed within a given square.For this, we will be given with the side of a square and our task is to find the side of the largest octagon that can be inscribed in it.Finding the relation between the sides of the square and the octagon, we find the formula for the side of the octagonside of square/(√2 + 1)Example#include using namespace std; //calculating the side of the octagon float calc_oside(float a) {    if (a < 0)       return -1;   ... Read More

Find the Smallest Element Among Three Elements in C++

Ayush Gupta
Updated on 09-Jul-2020 08:54:23

2K+ Views

In this tutorial, we will be discussing a program to find the smallest element among the provided three elements.We will be provided with three elements/ integers and our task is to compare them and find the smallest element/ integer among them.Example#include using namespace std; int main() {    int a = 45, b = 72, c = 10;    if (a

Find Sum of Each Row and Column of a Matrix in C++

Ayush Gupta
Updated on 09-Jul-2020 08:53:58

2K+ Views

In this tutorial, we will be discussing a program to find the sum of each row and each column for a given matrix.For this, we will be given with a say A*B matrix. Our task is to traverse through all the elements of the matrix and find the sum of each row and each column of the matrix.Example#include using namespace std; #define m 7 #define n 6 //calculating sum of each row void calc_rsum(int arr[m][n]){    int i,j,sum = 0;    for (i = 0; i < 4; ++i) {       for (j = 0; j < 4; ++j) {          sum = sum + arr[i][j];       }       cout

Find the Sum of the Series 1 + 2 + 3 + 4 + 5 + ... + n in C++

Ayush Gupta
Updated on 09-Jul-2020 08:53:33

371 Views

In this tutorial, we will be discussing a program to find the sum of the given series (1*1) + (2*2) + (3*3) + (4*4) + (5*5) + … + (n*n).For this, we will be given with the value of n and our task is to add up every term starting from the first one to find the sum of the given series.Example#include using namespace std; //calculating the sum of the series int calc_sum(int n) {    int i;    int sum = 0;    for (i = 1; i

Find the Sum of the Series 1^a + 2^a^2 + 3^a^3 + ... + n^a^n in C++

Ayush Gupta
Updated on 09-Jul-2020 08:53:06

149 Views

In this tutorial, we will be discussing a program to find the sum of the given series (1/a + 2/a^2 + 3/a^3 + … + n/a^n).For this, we will be given with the value of n and our task is to add up every term starting from the first one to find the sum of the given series.Example#include #include using namespace std; //calculating the sum of the series float calc_sum(int a, int n) {    int i;    float sum = 0;    for (i = 1; i

C++ Program to Find the Sum of the Series 1 + 1 + 2 + 2 + 3 + 3 + 4 + 4 + ... + n

Ayush Gupta
Updated on 09-Jul-2020 08:52:42

550 Views

In this tutorial, we will be discussing a program to find the sum of the given series 1/1! + 2/2! + 3/3! + 4/4! +…….+ n/n!.For this, we will be given with the value of n and our task is to add up every term starting from the first one to find the sum of the given series.Example#include using namespace std; //calculating the sum of the series double calc_sum(int n) {    int i;    double sum = 0, fact=1;    for (i = 1; i

Find the Sum of the Series 2+3, 4+5, 7+5 Up to N Terms in C++

Ayush Gupta
Updated on 09-Jul-2020 08:52:15

233 Views

In this tutorial, we will be discussing a program to find the sum of the given series 23+ 45+ 75+….. upto N terms.For this, we will be given with the value of N and our task is to add up every term starting from the first one to find the sum of the given series.After solving this, we get the formula for the sum of the series;Sn = (2n(n+1)(4n+17)+54n)/6Example#include using namespace std; //calculating the sum of the series int calc_sum(int N) {    int i;    int sum = (2 * N * (N + 1) * (4 * ... Read More

Find the Sum of the Series 1 + 1/2 + 2 + 1/3 + 3 + ... + 1/n in C++

Ayush Gupta
Updated on 09-Jul-2020 08:51:51

822 Views

In this tutorial, we will be discussing a program to find the sum of the given series 1 + 1/2^2 + 1/3^3 + …..+ 1/n^n.For this, we will be given with the value of n and our task is to add up every term starting from the first one to find the sum of the given series.Example#include #include using namespace std; //calculating the sum of the series double calc_sum(int n) {    int i;    double sum = 0.0, ser;    for (i = 1; i

C++ Program for Deadlock-Free Condition in Operating Systems

Sunidhi Bansal
Updated on 09-Jul-2020 08:50:06

4K+ Views

Given with the P number of processes in the memory and N number of needed resources by them to complete their execution and the task is to find the minimum number of resources R which should be allotted to the processes such that deadlock will never occur.What is a DeadlockDeadlock is situation in an operating system where multiple processes residing in the memory doesn’t able to perform their execution because the resources which are needed for program execution is being hold by another resource who is waiting for some other resource for completion.Let’s say there are two processes P1 and ... Read More

Advertisements