0% found this document useful (0 votes)
26 views3 pages

Assingment 2

This document contains code for Assignment 2 for the CSC415 course. It includes code for two questions. The first question code takes in three numbers as input and outputs the largest number. The second question code takes in coefficients a, b, and c as input for a quadratic equation, calculates the discriminant, and outputs the number and values of the roots depending on the discriminant.

Uploaded by

FaizAkmal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views3 pages

Assingment 2

This document contains code for Assignment 2 for the CSC415 course. It includes code for two questions. The first question code takes in three numbers as input and outputs the largest number. The second question code takes in coefficients a, b, and c as input for a quadratic equation, calculates the discriminant, and outputs the number and values of the roots depending on the discriminant.

Uploaded by

FaizAkmal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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