Professional Documents
Culture Documents
Experiment 5
Experiment 5
Input:
#include <iostream>
#include <cmath>
using namespace std;
int main() {
cout<<"Find the roots of quadratic equation \nName: Ayush \nRoll no. 3554"<<endl;
int a, b, c;
char chk;
float r1, r2, disc, realPart, imgPart;
chk='y';
while(chk=='y'||chk=='Y')
{cout << "Enter coefficients a b and c: ";
cin >> a >> b >> c;
disc = b*b - 4*a*c;
if (disc > 0) {
r1 = (-b + sqrt(disc)) / (2*a);
r2 = (-b - sqrt(disc)) / (2*a);
cout << "Roots are real and different." << endl;
cout << "r1 = " << r1 << endl;
cout << "r2 = " << r2 << endl;
}
else if (disc == 0) {
cout << "Roots are real and same." << endl;
r1 = -b/(2*a);
cout << "r1 = r2 =" << r1 << endl;
}
else {
realPart = -b/(2*a);
imgPart =sqrt(-disc)/(2*a);
cout << "Roots are complex and different." << endl;
cout << "r1 = " << realPart << "+" << imgPart << "i" << endl;
cout << "r2 = " << realPart << "-" << imgPart << "i" << endl;
}
cout<<"\nWant To Publish New List? (Y or N)";
cin>>chk;
}
return 0;
}
}
#include<iostream>
using namespace std;
int main()
{cout<<"To Create a 2-D Array and Print it Like a Matrix \nName: Aayush \nRoll
no. 3554"<<endl;
char chk;
chk='y';
while(chk=='y'||chk=='Y')
{
int rows, cols, i, j;
cout<<"Enter Rows for Array: ";
cin>>rows;
cout<<"Enter Columns for Array: ";
cin>>cols;
int arr[rows][cols];
cout<<"\nEnter "<<rows<<"*"<<cols<<" Array Elements : \n";
for(i=0; i<rows; i++)
{for(j=0; j<cols; j++)
{cout<<" ";
cin>>arr[i][j];}}
cout<<"\nTwo Dimensional Array is : \n";
for(i=0; i<rows; i++)
{for(j=0; j<cols; j++)
{cout<<" "<<arr[i][j]<<" ";}
cout<<"\n";}
cout<<"\nWant to perform again? (Y or N): ";
cin>>chk;
}
return 0;
}