CBSE eBooks

CBSE Guess > eBooks > Class XII > Computer Science By . Mr. MRK

Chapter – 1 C++ Revision Tour

Previous Index Next

1.e. Write the output of the following program: 3

#include<iostream.h>
int func(int &x,int y=10)
{
if(x%y==0) return ++x;
else return y- -;
}
void main( )
{
int p=20,q=23; q=func(p,q);
cout<<p<<q<<endl;
p=func(q); cout<<p<<q<<endl;
q=func(p);
cout<<p<<q<<endl;
}

Ans: Output:

2023
1023
1111

1. f. Write a function seqsum( ) in C++ with two arguments, double x and int n. The function should return a value of type double and it should find the sum of the following series. 4

Ans: 1+ x/2! + x /4! + x /6! + x /8! + x /10! + ----------+ x /(2n)!

#include<iostream.h>
#include<math.h>
#include<conio.h>
double seqsum(int x1,int m1);
void main()
{
int x; int m;
clrscr();
cout<<"Enter the vaue of X and M";
cin>>x>>m;
cout<<"\nThe sum of the series = "<<seqsum(x,m);
getch();
}
double seqsum(int x1,int m1)
{
double sum=1;
for(int i=1;i<=m1;i++)
{
int f=1;

for(int j=1;j<=2*i;j++)
{
f=f*j;

}
sum=sum+pow(x1,i)/f;
}
return sum;
}

1999 Annual Paper:

1.a. Why main( ) function is so special. Give two reasons? 1

Ans: Execution of the program starts and ends at main( ). The main( ) is the driver function of the program. If it is not present in a program, no execution can take place.

1.b. Name the header file of C++ to which following functions belong.

  1. strcat( )
  2. scanf( )
  3. getchar( )
  4. clrscr( )

Ans:

  1. strcat( ) - string.h
  2. scanf( ) - stdio.h
  3. (iii)getchar( ) - stdio.h
  4. clrscr( ) - conio.h

1.c. Find the syntax error(s), if any, in the following program:

#include<iostream.h>
main( )
{
int x[5],*y,z[5];
for(i=0;i<5;i++)
{
x[i]=i; z[i]=i+3; y=z; x=y;
}
}

Ans: (i) Line No 5: Undefined symbol ‘i’. The variable ‘i’ is not declared in the program.
(ii)Line No 10:Assign the value of a pointer to an integer variable. Ie error in x=y.

Ans: Output: First =8second =2

Previous Index Next