COMPUTER SCIENCE C++

1.d) Write the output of the following program.

void main( )
{ int x=5,y=5;
cout<<x- -;
cout<<”,”;
cout<- - x;
cout<<”,”;
cout<<y- -<<”,”<<- -y;
}

2

Ans:

Output: 5,3,4,4

1.e) Write the output of the following program.

#include<iostream.h>
void X(int &A,int &B)
{ A=A+B;
B=A-B;
A=A-B;
}
void main( )
{ int a=4,b=18;
X(a,b);
cout<<a<<”,”<<b;
}

3

Ans:

Output: 18,4

f) Write a function called zero_Small() that has two integer arguments being passed by reference and sets the smaller of the two numbers to 0. Write the main program to access this function.

#include<iostream.h>
#include<conio.h>
void zero_Small(int &A,int &B)
{ if(A<B)
A=0;else
B=0;
}
void main( )
{ clrscr();
int a,b;
cout<<”Enter any two values…”;
cin>>a>>b;
cout<<"Initial values of a and b are ";
cout<<a<<" "<<b<<endl;
zero_Small(a,b);
cout<<endl<<"The final values of a and b are ";
cout<<a<<","<<b;
cout<<endl;
cout<<"\nPress any key to continue...";
getch();
}

4

 

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