Tuesday 16 September 2014

write a c+program to find the sum of odd numbers and even numbers from 1 to N.

#include<iostream>
using namespace std;
int main()
{   int n;
    int sum=0,sum1=0;
cout<<"enter the number of element"<<endl;
cin>>n;
for(int i=0;i<=n;i++)
{
if(i%2==0)
{

sum=sum+i;

}


}
cout<<"sum of even number is = "<<sum<<endl;
for(int i=0;i<=n;i++)
{
if(i%2!=0)
{

sum1=sum1+i;

}


}
cout<<"sum of odd number is = "<<sum1;
}

write a c++ program to find the GCD and LCM of two integers output the resuls along with the given integers.use Euclid's distance.

#include<iostream>
using namespace std;
int main()
{   int num1,num2;
    int m1,m2,r;
cout<<"enter two numbers"<<endl;
cin>>num1>>num2;
if(num1>num2)
{
  m1=num1;
  m2=num2;
}
else
{ m1=num2;
 m2=num1;

}
while(r!=0)
{
r=m1%m2;
m1=m2;
m2=r;
}
cout<<"result of gcd of two number is "<<m1<<endl;
int lcm= (num1*num2)/m1;
cout<<"result of lcm of two number is "<<lcm;
}

write a c++ program to simulate a simple calculator to perform addition,substraction,multiplication and devision only on integer.

#include<iostream>
using namespace std;
int main()
{
char ch;
int a,b,result;
cout<<"enter two value "<<endl;
cin>>a>>b;
cout<<"enter the operator";
cin>>ch;

switch(ch)
{

      case '+':
              result=a+b;
              cout<<result;
              break;
      case '-':
            result=a-b;
            cout<<result;
            break;
      case '*':
              result=a*b;
            cout<<result;
            break;
      case '/':
            result=a/b;
            cout<<result;
            break;
      default:
        cout<<"enter correct operator";
        break;
}
}

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

Tuesday 24 June 2014

47)write aprogram to evaluate the square cube and 4th power of a number

#include<iostream>
#include<cmath>
using namespace std;
int main()
{   int k;
    int x2,y3,z4;
   cout<<"enter the value of k"<<endl;
   cin>>k;
   x2=k*k;
   y3=x2*k;
   z4=y3*k;
   cout<<"the square  of k is "<<x2<<endl<<"the 3rd power of k is"<<y3<<endl<<"the 4th power of k is"<<z4;
   int i;
    cin>>i;
    return 0;
}

46)write a program to evaluate the difference between bool and int data type.

#include<iostream>
using namespace std;
int main()
{   int k=10;
   int x;
   bool z;
    z=k<15;
    x=k<4;
    x=5;
   // x=5;
    //cout<<sizeof(x)<<endl<<sizeof(z)<<endl;
    cout<<"value of z"<<z<<endl<<"value of x"<<x;
    int i;
    cin>>i;
    return 0;
}

45)write a c++ program to read an angle in degrees and evaluate and display its sine and cosine.

#include<iostream>
#include<cmath>
using namespace std;
#define pi 3.14
int main()
{   float x,theta;
    float sx,cx;
    cout<<"ener the angle in degree"<<endl;
    cin>>theta;
    x=(180/pi)*theta;
    sx=sin(x);
    cx=cos(x);
    cout<<"sine of "<<theta<<"is"<<sx;
    cout<<"cosine of "<<theta<<"is"<<cx;
    int i;
    cin>>i;
    return 0;
}

Monday 23 June 2014

43)write a program to evaluate and display the volume of a cyclinder given its area and height.

#include<iostream>
using namespace std;
#define PI 3.14
int main()
{ float radius,height,volume;
  cout<<"enter radius of cylinder  "<<endl;
  cin>>radius;
  cout<<"enter height of cylinder  "<<endl;
  cin>>height;
  volume=PI*radius*radius*height;
 cout<<"the volume of cylinder is "<<volume;
}

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