CBSE Computer Science - Revision Tour(Solved)

CBSE Guess > eBooks > Class XII > CBSE Computer Science C++ Solved Revision Tour By Mr. Ravi Kiran

COMPUTER SCIENCE C++

Previous Index Next

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:

Global Variable

Local Variable

1- It is a variable, which is declared outside all the functions
2. It is accessible throughout the
program

1.It is a variable, which is declared with in a function or with in a compound statement
2 It is accessible only within a function/compound statement in which it is declared

#include <iostream.h>
float NUM=900; //NUM is a global variable
void LOCAL(int T)
{ int Total=0; //Total is a local variable
for (int I=0;I<T;I++)
Total+=I;
cout<<NUM+Total;
}
void main()
{ LOCAL(45);
}

(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)

 

Previous Index Next

CBSE Computer Science Solved Revision Tour By Mr. Ravi Kiran ( [email protected] )