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

ASSIGNMENT # 02

Program # 01
#include <iostream>
#include <math.h>
using namespace std;

int main(int argc, char** argv) {


float a,b,c,d,disc,e;
cout<<"enter the values of a,b and c";
cin>>a>>b>>c;
disc=b*b-4*a*c;
cout<<"discriminant="<<disc<<endl;
if(disc>0)
{

d=(-b+sqrt(disc)/(2*a));
e=(-b-sqrt(disc)/(2*a));
cout<<"root 1 is"<<d<<endl;
cout<<"root 2 is"<<e<<endl;
}
else if(disc<0)
{
cout<<"roots are not real";
}
else if(disc==0){
cout<<"there is no solution";}
return 0; }

Result:

Program # 02
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int a,b;
char op;

cout<<"enter first number: \n";


cin>>a;
cout<<"enter operator from (+,-,*,/) \n";
cin>>op;
cout<<"enter second number: \n";
cin>>b;
switch(op)
{
case'+':
cout<<"sum is"<<a+b;
break;
case'-':
cout<<"difference is"<<a-b;
break;
case'*':
cout<<"multiplication of numbers is"<<a*b;
break;
case'/':
cout<<a/b;
break;
default:
cout<<"operator you enter is incorrect";
break;
}
system("pause");
}

Result:
PROGRAM # 03:
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int n,t1=0,t2=1,nextterm=0;
cout<<"enter number of terms:";
cin>> n;
cout<<"Fibn=Fibn-1+Fbin-2 \n";
cout<<"fibonacci series:";
for(int i=1;i<=n;++i)
{
if(i==1)
{
cout<<t1;
continue;
}
if(i==2)
{
cout<<t2;
continue;
}
nextterm=t1+t2;
t1=t2;
t2=nextterm;
cout<< nextterm; }

Result:

You might also like