You are on page 1of 3

Assingment 2

CSC415

Lecturer : Dr Noor Elaiza Abdul Khalid


Student Name : Muhammad Faiz Akmal bin Maiden
Matric No. : 2017405158
Group : CS2421A
Question 1

#include<iostream>
using namespace std;
main ()

{
int no1, no2, no3;

cout << " Enter first number : ";


cin >> no1;
cout << " Enter second number : ";
cin >> no2;
cout << " Enter third number : ";
cin >> no3;

if(no1 >= no2 && no1 >= no3)


cout << " The largest number is " << no1 << endl;

else if(no2 >= no1 && no2 >= no3)


cout << " The largest number is " << no2 << endl;

else if(no3 >= no1 && no3 >= no2)


cout << " The largest number is " << no3 << endl;

system ("pause");
return 0;
}
Question 2

#include <iostream>
#include <cmath>
using namespace std;

main ()
{
float a,b,c,x1,x2, discriminant;

cout<<" Enter the coefficients a : ";


cin>>a;
cout<<" Enter the coefficients b : ";
cin>>b;
cout<<" Enter the coefficients c : ";
cin>>c;
discriminant = b*b - 4*a*c;

if(a==0 && b==0)


cout<<" The function have no solution " <<endl;

else if(a==0)
{
cout<<" The function have one root "<<endl;
x1=x2= (-c/b);
cout<<" The root is equal to " << x1 <<endl;
}

else if(discriminant>0)
{
x1 = (-b + sqrt(discriminant)) / (2*a);
x2 = (-b - sqrt(discriminant)) / (2*a);
cout << " The funtion have two different roots. " <<endl;
cout << " x1= " << x1 <<endl;
cout << " x2= " << x2 <<endl;

else if(discriminant<0)
{
cout << "The funtion have no real root " <<endl;

return 0;

You might also like