C++ PROGRAMS

QUADRATIC EQUATION



 #include<iostream.h>
#include<conio.h>
#include<math.h>


 main()
{
 clrscr();    
 float root1,root2,a,b,c,d;
 cout<<"Quadratic Equation is ax^2=bx+c=0";
 cout<<"\n  Enter values of a,b and c:";
 cin>>a>>b>>c;


 d=(b*b)-(4*a*c);
 if(d>0)
 {
       cout<<"\nTwo real and distinct roots";
       root1=(-b+sqrt(d))/(2*a);
       root2=(-b-sqrt(d))/(2*a);
       cout<<"\nRoots are "<<root1<<" and "<<root2;
 }


 else
  if(d==0)
  {
         cout<<"\nTwo real and equal roots";
         root1=root2=-b/(2*a);
         cout<<"\nRoots are "<<root1<<" and "<<root2;
  }
  else
      cout<<"\nRoots are COMPLEX and IMAGINARY....!!!";
 getch(); 
}

__________________________________________________________________________________
INCOME TAX AND SALARY

#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
float incometax, salary;
cout<<"enter salary";
cin>>salary;
if (salary<=60000)
{
incometax=0;
}
if (salary>60000 && salary<=100000)
{ cout<<"payable tax";
incometax=(salary-60000)*(10/100);
}
if(salary>100000 && salary<=150000)
{ cout<<"payable tax";
incometax=10000;
}
if (salary>150000)


{  cout<<"payable tax";
incometax=(10000)+(salary-150000)*(30/100);
}
cout<<incometax;
getch();
}
__________________________________________________________________________________

INTERCHANGING THE VALUE OF TWO INTEGERS
#include<iostream.h>
#include<conio.h>
main()
{ clrscr();
int a,b;

cout<<"\n the value of a is";
cin>>a;
cout<<"\n the value of b is";
cin>>b;
a=a+b;
b=a-b;
a=a-b;

cout<<a;
cout<<b"\n value of b";
getch();
}
__________________________________________________________________________________
                                              FIBONACCI SERIES

#include <iostream>
using namespace std;

int main()
{
   cout<<"Enter the number of terms in the Fibonacci series>";
   int numOfTerms;
   cin>>numOfTerms;
   int fib1 = 0;
   int fib2 = 1;
   int fib = 0;
   if (numOfTerms >= 1)
      cout<<"F["<<numOfTerms<<"] = "<<fib1;
      if (numOfTerms >= 2)
      {
         cout<<" + "<<fib2;
         for (int x = 2; x < numOfTerms; x++)
         {
            fib = fib + fib2;
            cout<<" + "<<fib;
            fib1 = fib2;
            fib2 = fib;
         }
      }
   int sum;
   if (numOfTerms >= 1)
      {
         sum = numOfTerms - 1 + numOfTerms - 2;
         cout<<" = "<<sum;
      }
   else
      cout<<endl;
   return 0;
}
                     FACTORIAL OF A NUMBER

#include<iostream.h>
#include <conio.h> //For clrscr()//


int main()
{
clrscr();
int i, n, fact;
cout<<"\nEnter the Value of n \n";
cin>>n;
for(i=n ; i>=1 ; i--)
fact = n*i;
cout<<"\nFactorial => "<<fact;
getch();
return(0);
}

__________________________________________________________________________________________
                                   
            ARMSTRONG NUMBER
                            

To find if the given number is an armstrong number or not


# include <iostream.h>
# include <conio.h>
# include <math.h>
 void main ()
{ clrscr();
 int a,b=0,sum=0;
 long int n;
 cout<<"ENter the NO. : ";
 cin>>n;
 for(;n>0;)
//counts the digits
 { a=n%10;
   n=n/10;
   b++;
 }
 for(;n>0;)
 { a=n%10;
   sum=sum+pow(a,b);
   n=n/10;
 }
  if(sum==n)
 { cout<<"IT IS AN ARMSTRONG NUMBER...";
  getch();
 }
  else
 { cout<<"IT IS NOT AN ARMSTRONG NUMBER...";
   getch();
 }
}
__________________________________-




                   PRIME NUMBER              

#include<iostream>
using namespace std;

int main(){
  int num;
  bool prime;

  cout << "Please enter a positive integer" << endl;
  cin >> num;

  for(int i = 3; i <= num; i++){
    prime = true;
    for(int n = 2; n <= i - 1; n++){
      if(i % n == 0){
        prime = false;
      }
    }
    if(prime){
      cout << i << " is prime" << endl;
    }
  }

  return 0;
}
__________________________________________________________________________________

        PALINDROME OF A NUMBER
#include<stdio.h>
#include<conio.h>

main()
{
int rev=0,num=0,rem;
printf("enter the number");
scanf("%d",&num);

if(num>0)
 {
  num=num/10;
rev=rev*10+num;
rem=rem%10;
}
printf("the palindrome of number is ",rev);

_________________________________________
         TEMPERATURE CONVERTER
#include <iostream>
using namespace std;
 
int main()
{
    char option;
    float degrees;
 
    cout << "Press 1 or 2 to convert From :" << endl;
    cout << "[1] Celsius to Fahrenheit" << endl;
    cout << "[2] Fahrenheit to Celsius" << endl;
 
    cin >> option;
 
    if (option == '1')
    {
        cout << "Please enter the number of Celsius Degrees:" << endl;
        cin >> degrees;
        float fahren = (degrees * 1.8) + 32;
        cout << degrees << " degrees Celsius is " << fahren << " degrees Fahrenheit" << endl;
    }
    else
    {
        cout << "Fahrenheit to Celsius" << endl;
        cin >> degrees;
        float celsius = (degrees - 32) / 1.8;
        cout << degrees << "degrees Fahrenheit is " << celsius << "degrees Celsius"<< endl;
    }
 
    return 1;
}___________________________________________________________________________________              
                    DECIMAL TO BINARY
Void main()
{
   int dec,i=1,rem,res=0;
   Printf("Enter the Value %d",&dec);
   while(dec!=0)
    {
        rem=dec%2;
        dec=dec/2;
        res=res+(i * 1);
        i=i*10;

    }
printf("The Binary value is %d",res);
}

 
Design by Free Wordpress Themes | Bloggerized by Free Blogger Templates | Web Hosting Deals