RSS

Category Archives: Getting Started

FUNCTION TO PERFORM SUM OF THE SERIES GIVEN

/* FUNCTION TO PERFORM THE SUM OF THE FOLLOWING SERIES

x – x^2/3! + x^3/5! – ….. upto n terms */

#include <iostream>

double sumseries(double x, int n);

using namespace std;

int main()
{
int n;
double x;

cout<<“\nEnter the value of ‘x’ \n”;
cin>>x;
cout<<“\nEnter the number of terms\n”;
cin>>n;

double result = sumseries(x,n);
cout<<“\nThe result is “<<result;

return 0;
}

double sumseries(double x, int n)
{
double sumo = 0.0, sume = 0.0;
double val = 1.0;
double fact = 1;
for(int i = 1; i<= n; i++)
{
val = 1;
fact = 1;
for(int j = 1; j<=i; j++)
{
val *= x;
}
for(int k = 2*i – 1; k>1; k–)
{
fact *= k;
}
if(i%2 == 0)
{
sume += val/fact;
}
else
{
sumo += val/fact;
}
}

return (sumo – sume);
}

Advertisements
 
Leave a comment

Posted by on November 21, 2015 in Functions, Getting Started

 

PROGRAM TO FIND THE AVERAGE OF THREE NUMBERS

//THIS PROGRAM FINDS THE AVERAGE OF THREE NUMBERS
#include <iostream.h>
#include <conio.h>

void main()
{
clrscr();
float a,b,c;
cout<<“Enter the numbers\n”;
cin>>a>>b>>c;
float result=(a+b+c)/3;
cout<<“\nThe result is \n”<<result;
getch();
}

 
Leave a comment

Posted by on March 2, 2015 in Getting Started

 

PROGRAM TO MULTIPLY TWO NUMBERS

//THIS PROGRAM MULTIPLIES TWO NUMBERS
#include <iostream.h>
#include <conio.h>
#include <iomanip.h>

void main()
{
clrscr();
int a,b;
cout<<“Enter the numbers\n”;
cin>>a>>b;
int result=a*b;
cout<<“\nThe product is \n”<<setprecision(2)<<result;
getch();
}

 
Leave a comment

Posted by on March 2, 2015 in Getting Started

 

PROGRAM TO DIVIDE TWO NUMBERS

//THIS PROGRAM DIVIDES TWO NUMBERS
#include <iostream.h>
#include <conio.h>
#include <iomanip.h>

void main()
{
clrscr();
float a,b;
cout<<“Enter the numbers\n”;
cin>>a>>b;
float result=a/b;
cout<<“\nThe division yeilds \n”<<setprecision(2)<<result;
getch();
}

 
Leave a comment

Posted by on March 2, 2015 in Getting Started

 

PROGRAM TO SUBTRACT TWO NUMBERS

//THIS PROGRAM SUBTRACTS TWO NUMBERS
#include <iostream.h>
#include <conio.h>

void main()
{
clrscr();
int a,b;
cout<<“Enter the numbers\n”;
cin>>a>>b;
int result=a-b;
cout<<“\nThe difference is \n”<<result;
getch();
}

 
Leave a comment

Posted by on March 2, 2015 in Getting Started

 

PROGRAM TO PRINT THE ROOTS OF A QUADRATIC EQUATION (REAL ROOTS ONLY)

/*THIS PROGRAM CHECKS IF THE EQUATION HAS REAL ROOTS OR NOT
AND PRINTS THE VALUE of `x’ IF ROOTS EXIST */

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

void main()
{
clrscr();
int a,b,c;
cout<<“Enter the values of a,b and c respectively\n”;
cin>>a>>b>>c;
int d=b*b-4*a*c;
if(b*b-4*a*c>=0)
{
cout<<“\nRoots Exist.\nRoots are:-\n”;
int root;
root=(-b+sqrt(d))/2*a;
cout<<root<<“\n”;
root=(-b-sqrt(d))/2*a;
cout<<root<<“\n”;
}
else
{
cout<<“\nRoots do not exist\n”;
}
getch();
}

 
Leave a comment

Posted by on March 2, 2015 in Getting Started

 

PROGRAM TO FIND IF A YEAR IS LEAP OR NOT

//THIS PROGRAM FINDS IF A YEAR IS LEAP OR NOT

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

void main()
{
clrscr();
int year;
cout<<“Enter a Year\n”;
cin>>year;
if(year%4==0)
{
cout<<“\nThe year is Leap\n”;
}
else
{
cout<<“\nThe year is not Leap\n”;
}
getch();
}

 
Leave a comment

Posted by on March 2, 2015 in Getting Started