Linear Search ( C++ program )
# include "iostream"
# include "conio.h"
using namespace std;
int main()
{
int
a[100],n,item,s=0;
cout<<"Enter No. of Elements :
";
cin>>n;
cout<<"\nEnter Elements=\n";
for(int
i=1;i<=n;i++)
{
cin>>a[i];
}
cout<<"\nEnter Element you want to
Search=";
cin>>item;
for(int
i=1;i<=n;i++)
{
if(a[i]==item)
{
cout<<"\nData is Found at Location :
"<<i;
}
if(s==0)
{
cout<<"Data is Not Found";
}
getch();
}
Decimal to Binary Conversion ( C++ program )
# include "conio.h"
# include "iostream.h"
using namespace std;
int main()
{
long dec,rem,i=1,sum=0;
cout<<"Enter Decimal Value:";
cin>>dec;
do
{
rem=dec%2;
sum=sum + (i*rem);
dec=dec/2;
i=i*10;
}
while(dec>0);
cout<<"The binary is:" <<sum <<endl;
getch();
}
Factorial ( C++ program )
# include "conio.h"
# include "iostream.h"
int main()
{
int n,fact=1;
cout << endl << "Factorial !!! Enter Any No: ";
cin >> n;
for(int i=n;i>=1;i--)
{
fact=fact*i;
}
cout << endl << "The Factorial Of " << n << " is " << fact;
getch();
}
# include "iostream.h"
int main()
{
int n,fact=1;
cout << endl << "Factorial !!! Enter Any No: ";
cin >> n;
for(int i=n;i>=1;i--)
{
fact=fact*i;
}
cout << endl << "The Factorial Of " << n << " is " << fact;
getch();
}
Quadratic Equation ( C++ program )
# include "conio.h"
# include "iostream"
# include "stdio.h"
# include "math.h"
using namespace std;
int main()
{
float a,b,c,d,root1,root2;
cout << "Quardatic Equation Solver" << endl << endl;
cout<<"Enter value of a, b and c : ";
cin>> a>>b>>c;
d=b*b-4*a*c;
if(d==0)
{
root1=(-b)/(2*a);
root2=root1;
cout<<"Roots are Real & Equal";
}
else if(d>0)
{
root1=-(b+sqrt(d))/(2*a);
root2=-(b-sqrt(d))/(2*a);
cout<<"Roots are Real & Distinct";
}
else
{
root1=(-b)/(2*a);
root2=sqrt(-d)/(2*a);
cout<<"Roots are Imaginary";
}
cout<<"\nRoot 1= "<<root1<<"\nRoot 2= "<<root2;
getch();
}