1.f) Write a C++ function having two value parameters X and N with result type float to find the sum of series given below: 1 + x1/2! + x2/3! + x3/4! + x4/5! + - - - - - - xn/(n+1)!
#include<iostream.h>
#include<conio.h>
#include<math.h>
float sum_series(float X,int N) //function
being declared
{ float sum=0,term;
int fact,f;
sum+=1;
for(int i=1;i<=N;i++)
{ fact=1;
for(f=1;f<=(i+1);f++)
fact*=f;
term=pow(X,i)/fact;
sum+=term;
}
return(sum);
}
void main( )
{ clrscr( );
float x1;
int n1;
cout<<"\nEnter the value of X and N";
cin>>x1>>n1;
cout<<"\nThe Sum of the Series ..."<<sum_series(x1,n1);
getch(); }
Model Paper 1 for 2008-09 Batch
Q1. (a) What is the difference between Global Variable and Local Variable?
2
Answer:
|
|
|
|
|
(1/2 Mark for each point of difference)(1/2 Mark for example of Global Variable) (1/2 Mark for example of Local Variable) OR (Full 2Marks to be awarded if the difference is explained with the help of suitable example)
CBSE Computer Science Solved Revision Tour By Mr. Ravi Kiran ( [email protected] )