Upperlower I Quad

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

/* C++ program to find roots of a quadratic equation */

#include <bits/stdc++.h>
using namespace std;

// Prints roots of quadratic equation ax*2 + bx + x


void findRoots(int a, int b, int c)
{
// If a is 0, then equation is not quadratic, but
// linear
if (a == 0) {
cout << "Invalid";
return;
}

int d = b * b - 4 * a * c;
double sqrt_val = sqrt(abs(d));

if (d > 0) {
cout << "Roots are real and different \n";
cout << (double)(-b + sqrt_val) / (2 * a) << "\n"
<< (double)(-b - sqrt_val) / (2 * a);
}
else if (d == 0) {
cout << "Roots are real and same \n";
cout << -(double)b / (2 * a);
}
else // d < 0
{
cout << "Roots are complex \n";
cout << -(double)b / (2 * a) << " + i" << sqrt_val / (2 * a)
<< "\n"
<< -(double)b / (2 * a) << " - i" << sqrt_val / (2 * a) ;
}
}

// Driver code
int main()
{
int a = 1, b = -7, c = 12;

// Function call
findRoots(a, b, c);
return 0;
}

debug assertion failed

=========================
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
int a,b,c; // constants of equation
float x1,x2; //roots
cout<<"Enter value of a: ";
cin>>a;
cout<<"Enter value of b: ";
cin>>b;
cout<<"Enter value of c: ";
cin>>c;
int D;
D= b*b - 4*a*c; // determinant
if(D>=0){ //nature of roots
if(D==0)
cout<<"Roots are real and equal: ";
else
cout<<"Roots are real and distinct: ";
x1=(-b+ sqrt(D))/(2*a); // roots calculation by quadratic
formula
x2=(-b- sqrt(D))/(2*a);
cout<<x1<<", "<<x2;
}
else
cout<<"Roots are imaginary!";
return 0;
}

=============================

#include <iostream>
using namespace std;

void lower_string(string str)


{
for(int i=0;str[i]!='\0';i++)
{
if (str[i] >= 'A' && str[i] <= 'Z') //checking for uppercase
characters
str[i] = str[i] + 32; //converting uppercase to lowercase
}
cout<<"\n The string in lower case: "<< str;
}

void upper_string(string str)


{
for(int i=0;str[i]!='\0';i++)
{
if (str[i] >= 'a' && str[i] <= 'z') //checking for lowercase
characters
str[i] = str[i] - 32; //converting lowercase to uppercase

}
cout<<"\n The string in upper case: "<< str;
}

int main()
{
string str;
cout<<"Enter the string ";
getline(cin,str);
lower_string(str); //function call to convert to lowercase
upper_string(str); //function call to convert to uppercase
return 0;
}

You might also like