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);
}

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...