Friday 25 July 2014

program to generate the first 20 terms of the facobian series by using recursion .

#include<iostream>
using namespace std;
int facob(int );
int main()
{
int i;
for(i=1;i<=20;i++)
cout<<facob(i)<<" ";
}

int facob(int i)
{
if(i==1)
return(0);
else if(i==2)
return(1);
else
return(facob(i-2)+facob(i-1));
}

program to display the multiplication table of a number.it uses recursion.

#include<iostream>
#include<iomanip>
#include<iostream>
using namespace std;
int product(int k, int i);

int main()
{
int i, k;
cout<<"enter any integer number ";
cin>>k;
for(i=1;i<=10;i++)
cout<<setw(4)<<k<<"*"<<setw(3)<<i<<"="<<setw(4)<<product(k,i)<<endl;
}

//function to evaluate the factorial
int product(int k,int i)
{
if(i==1)
 return(k);
else
 return(product(k,i-1)+k);
}

write a program to read an integer number and evaluate its factorial by recursion.

#include<iostream>
using namespace std;
float factorial(int);

int main()
{
int k;
cout<<"enter the number ";
cin>>k;
cout<<"factorial of"<<k<<"is"<<factorial(k);
}

//function to evaluate the factorial
float factorial(int n)
{
if(n==0)
 return(1);
else
 return(n*factorial(n-1));
}

Sunday 13 July 2014

program to find the reciprocal of five numbers.it ignores zero ,if entered.

#include<iostream>
#include<cmath>
#include<stdlib.h>
#define esp 0.000001
using namespace std;
int main()
{
int n,i;
float sum=0;

for(i=1;i<+5;i++)
{
cout<<"enter the number  "<< i<<endl;
cin>>n;

if(n==0)
{
cout<<"zero is not define";
continue;

}
sum=sum+1/n;
}
cout<<"the sum is"<<sum<<endl;
}

Tuesday 8 July 2014

53)program to find the sum of reciprocal of integer numbers.

#include<iostream>
using namespace std;
#define AND &&
int main()
{
float n1,n2,sum;

cout<<"enter the number n1";
reenter:

cin>>n1;
if(n1==0)
{   cout<<"reenter the number n1 "<<endl;
   cout<<"reciprocal of zero is not define";

        goto reenter;
}

n2=1/n1;
sum=n1+n2;
cout<<"sum of two reciprocal number is  "<<sum<<endl;

Sunday 6 July 2014

52)write a program to find out the amount after n periods,given the principle and the rate of interest.

#include <iostream>
#include<cmath>
using namespace std;
class fixeddeposit
{
  private:
  float p;
  int n;
  float r;
  float A;
  public:
  void setdata();
  void getamount();
};
void fixeddeposit::setdata()
 {
  cout<<"enter the value of p,n,and r"<<endl;
  cin>>p>>n>>r;
 }
 void fixeddeposit::getamount()
 {
  A=p*pow((1+r),n);
  cout<<"amount is  "<<A;
 }
 int main()
 {
  fixeddeposit b;
  b.setdata();
  b.getamount();
 }

Friday 4 July 2014

51)write a program to evaluate,depending upon the choice of the user,the area of either a circle,a rectangle or a triangle

#include<iostream>
#include<cmath>
#include<cstdlib>
# define PI 3.14
using namespace std;
void menu();
void area_circle();
void area_rectangle();
void area_triangle();
int option;
float AREA;
int main()
{
  //int option;

  menu();
  switch (option)
     {
        case 1:
            area_circle();
            break;
        case 2:
            area_rectangle();
            break;
         case 3:
            area_triangle();
            break;
     }
    cout<<"area is" <<endl<<AREA;
}
void menu()
{
//float a,b,c, AREA;
  cout<<"1 :circle"<<endl;
  cout<<"2 :rectangle"<<endl;
  cout<<"3 :triangle"<<endl;
  cout<<"your option"<<endl;
  cin>>option;
  //cout<<"the area is "<<AREA;
 
}
void area_circle()
{
int R;//,AREA;
cout<<"enter the radius";
cin>>R;
AREA=PI*R*R;
}
void area_rectangle()
{
float a,b;//,AREA;
cout<<"enter the width and height"<<endl;
cin>>a>>b;
AREA=a*b;
}

void area_triangle()
{
float s,a,b,c;//,AREA;
cout<<"enter the side of the triagle"<<endl;
cin>>a>>b>>c;
s=(a+b+c)/2.0;
AREA=s*(s-a)*(s-b)*(s-c);
AREA=sqrt(AREA);
}

Thursday 3 July 2014

50)program to find the multiplication table of a number.it uses two functions in addition to function main().

#include<iostream>
#include<cmath>
using namespace std;
void read_X();
void table_x();
int X,N=1,table;
void read_X()
{  cout<<"enter the number "<<endl;
cin>>X;
}
void table_x()
{ cout<<"The table of" <<X<< "is"<<endl;
while(N<=10)
{  cout<<X<<"*"<<N<<"= "<<X*N<<endl;
    N++;
}
}
int main()
{ //int X,N=1,table;
 
    read_X();
    table_x();


}

49).wright a program to find the slope of a line given the coordinates of its end points.

#include<iostream>
#include<cmath>
using namespace std;
#define PI 3.14
int slope(int x1,int y1, int x2,int y2)
{
   float tanx,s;
   tanx=(y2-y1)/(x2-x1);
   s=atan(tanx);
   s=(180/PI)*s;
   return s;
}
int main()
{ float x1,x2,y1,y2,x,tanx,s;
  while(true)
  {
      cout<<"enter the co_ordinate of point A";
      cin>>x1>>y1;
      cout<<"enter the co_ordinate of point B";
      cin>>x2>>y2;
      if(x2-x1==0)
      {
       cout<<"Slope is 90 degrees"<<endl;
       continue;
      }
       
      else
          s = slope(x1,y1,x2,y2);
      cout<<"slope of line AB"<<s<<"Degrees"<<endl;  
  }

}

48) write a program to find the multiplication table of a number

#include<iostream>
#include<cmath>
using namespace std;
#define PI 3.14
int main()
{ int i,n,table;
    cout<<"enter the number n"<<endl;
cin>>n;
    cout<<"The table of" <<n<< "is"<<endl;
for(i=1;i<=10;i++)
{
       table=n*i;
       cout<<"n*i= "<<table<<endl;
}

Write a program which reads a set of integers into an integer array and then prints "YES"if all of them are same otherwise print "NO".

#include<stdio.h> int main() { int a[10],M=0,i,n; printf("enter a value for n\n"); scanf("%d",&n); fo...