C++ Program To Calculate Standard
Deviation Of Given Numbers
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int n , j ,y;
double _sum=0 , variance;
cout << "How Many Numbers To
Type? ";
cin >> y;
cout << endl;
double max[y];
for(n=0;n<=y-1;n++) {
cout << "Enter Number "
<< n+1 << " : ";
cin >> max[n];
}
n=0;
cout << endl;
cout << "\nSo The Numbers
Are:\t";
for(j=0;j<=y-1;j++) {
cout << max[n] <<
"\t";
_sum+=max[n];
n++;
cout << endl << "\nSum:
"<< _sum << endl;
cout << "Mean: "
<< mean << endl;
n=0; j=0; _sum=0;
for(j=0;j<=y-1;j++) {
max[n]=pow((max[n]-mean),2);
_sum+=max[n];
n++;
}
variance=_sum/(n-1);
cout << "Variance: "
<< variance << endl;
cout << "Standard Deviation:
" << sqrt(variance) << "\n\n";
}
C++ Program To Find The Roots Of A
Quadratic Equation
#include <iostream>
#include <cmath>
using namespace std;
int main() {
float a, b, c, x1, x2, determinant,
realPart, imaginaryPart;
cout << "Enter The
Coefficients (a, b, c): " << endl;
cin >> a >> b >> c;
while (!a) {
cout << "The Value Of a
Cannot Be Zero." << endl;
cout << "\nEnter The
Coefficients (a, b, c): " << endl;
cin >> a >> b >> c;
}
determinant = b*b - 4*a*c;
if (determinant > 0) {
x1 = (-b + sqrt(determinant)) / (2*a);
x2 = (-b - sqrt(determinant)) / (2*a);
cout << "\nRoots Are Real And
Different." << endl;
cout << "x1 = " <<
x1 << endl;
cout << "x2 = " <<
x2 << endl;
}
else if (determinant == 0) {
cout << "\nRoots Are Real And
Same." << endl;
x1 = (-b + sqrt(determinant)) / (2*a);
cout << "x1 = x2 ="
<< x1 << endl;
}
else {
realPart = -b/(2*a);
imaginaryPart =sqrt(-determinant)/(2*a);
cout << "\nRoots Are Complex
And Different." << endl;
cout << "x1 = " <<
realPart << "+" << imaginaryPart << "i"
<< endl;
cout << "x2 = " <<
realPart << "-" << imaginaryPart << "i"
<< endl;
}
return 0;
}