COMPUTER SCIENCE C++

2001:

1.b) Name the header file to be included for the use of the following built in functions:(i) getc( ) (ii)strcat()

1

Ans:  (i) getc( ) - stdio.h
          (ii) strcat( ) - string.h

1.e) Give the output of the following programs:

#include<iostream.h>
#include<conio.h>
int g=20;
void func(int &x,int y)
{ x=x-y;
y=x*10;
cout<<x<<’,’<<y<<’\n’;
}
void main( )
{ int g=7;
func(g,::g);
cout<<g<<’,’<<::g<<’\n’;
func(::g,g);
cout<<g<<’,’<<::g<<’\n’;
}

Ans: Output:

-13,-130
-13,20
33,330
-13,33

1.f) Write a function named SUMFIN( ), with arguments x, N, which returns the sum of N terms of the following series. x – x^3/3 + x^5/5 – x^7/7 + x^9/9

#include<iostream.h>
#include<math.h>
#include<conio.h>
double SUMFIN(int x1,int n1);
void main()
{ int x;
int n;
clrscr();
cout<<"Enter the vaue of X and N";
cin>>x>>n;
cout<<”\nThe sum of Series = “<<SUMFIN(x,n);
getch();
}double SUMFIN(int x1,int n1)
{ double sum=0;
int c=0;
for(int i=1;i<=(2*n1);i=i+2)
{ c=c+1;
if(c%2==1)
{ sum=sum+(pow(x1,i))/i;
}
else
{ sum=sum-(pow(x1,i))/i;
}
}
return sum;
}

4

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