Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
50 views

Assignment#1: Name: Eysha Qureshi Reg. No: 130401032 EE-03-A Subject: Programming Language

1. c++ program to add two numbers entered by user. 2. c++ program to find the largest among three different numbers entered by user. 3. C++ program to find all the roots of a quadratic equation ax2+bx+c=0. 4. C++ program to find the Fibonacci series till term≤1000.

Uploaded by

Eysha qureshi
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)
50 views

Assignment#1: Name: Eysha Qureshi Reg. No: 130401032 EE-03-A Subject: Programming Language

1. c++ program to add two numbers entered by user. 2. c++ program to find the largest among three different numbers entered by user. 3. C++ program to find all the roots of a quadratic equation ax2+bx+c=0. 4. C++ program to find the Fibonacci series till term≤1000.

Uploaded by

Eysha qureshi
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/ 8

Assignment#1

Name : Eysha Qureshi

Reg. No : 130401032

EE-03-A

Subject: Programming Language

Dated: 25/03/2014
Submitted to: Sir Ghulam Abbas

C++ PROGRAMS
Program #1:
Q.Write a program to add two numbers entered by user.
//Sum of two numbers entered by users

#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
float num1,num2,sum;
cout<<" Enter the first number ";
cin>>num1;
cout<<" Enter the second number ";
cin>>num2;
sum=num1+num2;
cout<<" The sum of two numbers entered by the user is "<<sum<<endl;
cin.get();
getch();
}

Screen Shot
Program #2:
Q.Write a program to find the largest among three different numbers entered
by user.
//The largest number among three different numbers
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
float a,b,c;
cout<<"Enter the first number"<<endl;
cin>>a;
cout<<"Enter the second number"<<endl;
cin>>b;
cout<<"Enter the third number"<<endl;
cin>>c;
if (a>b)

{ if (a>c)
cout<<"The largest number is a="<<a<<endl;
else
cout<<"The largest number is c="<<c<<endl;
}
else
{ if (b>c)
cout<<"The largest number is b="<<b<<endl;
else
cout<<"The largest number is c="<<c<<endl;
}
cin.get();
getch();
}
Screen shot:
Program#3:
Q.Write a program to find all the roots of a quadratic equation ax2+bx+c=0.

//Roots of quadratic equation


#include<iostream>
#include<cmath>
#include<conio.h>
using namespace std;
void main()
{
float a,b,c,D,r1,r2,rp,ip;
cout<<"enter the number a"<<endl;
cin>>a;
cout<<"enter the number b"<<endl;
cin>>b;
cout<<"enter the number c"<<endl;
cin>>c;
D=pow(b,2)-4*a*c;
if (D>=0)
{ r1=(-b+sqrt(D))/(2*a);
r2=(-b-sqrt(D))/(2*a);
cout<<"First real root is"<<r1<<endl;
cout<<"Second real root is"<<r2<<endl;
}
else
{ rp=-b/(2*a);
ip=sqrt(-D)/(2*a);
cout<<"First imaginary root is x1="<<rp<<"+"<<"i"<<" "<<ip<<endl;
cout<<"Second imaginary root is x2="<<rp<<"-"<<"i"<<" "<<ip<<endl;
}
cin.get();
getch();
}

Screen shot:
Programe#4:
Q.Write a program to find the Fibonacci series till term≤1000.
//fibonacci series
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
int fterm,sterm,temp;
fterm=0;
cout<<"Fibonacci series:"<<endl;
for (sterm=1;sterm<=1000;)
{
cout<<sterm<<" ";
temp=sterm+fterm;
fterm=sterm;
sterm=temp;
}
cout<<endl;
cin.get();
getch();
}

Screen shot:

You might also like