You are on page 1of 6

// Eyoo parebrotsongs di ako sure sa mga sagot ko kayo na bahala. Goodluck!!

I. Modified True or False


Write True if the statement is correct, otherwise change the underlined word(s) to make the
statement correct.
True 1. The void functions in a program result either by reaching the end of the
function or by executing statement(s) with no returned value.
return statements 2. The value-returning functions return a value on a specific data type
using the u-turn statement.
True 3. A function is a/an sub-program that perform specific task.
parenthesis () 4. A function that has no parameter, still need the empty square brakets
[] in both function heading and the function call.
parenthesis () 5. The paramenter(s) list(s) in a function must put inside the curly
brackets {}.
True 6. The formal parameter is a variable declared in the function heading
Location (daw) 7. The pointer variable is a variable whose content is a/an empty (a
memory address).
True 8. In function call, the function name is the operand, simply calling the
function or sub-program.
& and * 9. The Special Characters: @ and $ , are used as pointers in functions.
True 10. In recursive function, the program must need a non-recursive branch,
otherwise the execution of function would never end.
II. Multiple Choice
Direction: Write the letter of the correct answer on the space provided. Write E if no correct
answer is given in the choices.
B. Local variable 1. What do you call the variable(s) used in when declared inside the
function?
A. return l; 2. In a function: int main() which means, main function should return
integer data type, what statement should be done?
a return l; b. no return no exchange, c. return 1.0; d u-turn 0; .
C. Global variable 3. What do you call the variable(s) used in when declared outside the
function?
A. void 4. What is the latest data type that added to the ISO - ANSI C?
A.star(); 5. What will be the valid statement in function call to execute void star in a
program?
B. & and * 6. To use the variable pointers, what are the 2 special characters to run a
program?
B. memory address 7. What signifies the special character ampersand (&) in a functions?
A. parameter list 8. What are the variables used in the call and pass function ?
A. function main 9. When the program executes, the execution always begins with the first
statement in _____.
B. return statement 10. The value-returning functions can return a value of a specific data
type using the _____.

III. Answer as required: (2 points each )


1. To print your name 10 times vertically using recursive function
Int func (int x) {
cout<<”MAMA MO”<<endl;
If (x>1)
func(x-1);
return 0; }
int main () {
int x=10;
func(x);
return 0; }

2. To display 10 to 1 vertically using recursive function


Int func (int x) {
cout<<x<<endl;
If (x>1)
func(x-1);
return 0; }
int main () {
int x=10;
func(x);
return 0; }

3. To declare a, b and c as formal parameter in function star


int star (int a, int b, int c)
4. How to use variables x, y and z in parameter lists on calling the function star?
*dito ako pinaka di sure*
star (x,y,z);
5. Display the sum of 1 to n (the value of n inputted by the user) using recursive function.
int func(int x) {
If (x>0)
return x + func (x-1);
else
return 0;
}
int main(){
int x;
cin>>x;
func(x);
cout<<func(x);
return 0;

IV. Trace the output: (5 points cach)


1. void star( int x, int y, int &z)
{
z=(x * x) + (y * y);
z=pow (z, 0.5);
}
main()
{
int x = 18, y = 24, z=0;
star (x, y, z);
cout< The value of x = "<< x << endl;
cout<<"The value of y="<< y << endl;
cout<<"The value of z="<<z<< endl; }

The value of x = 18
The value of y = 24
The value of z = 30

2. void star (int x, int y, int &z)


{
z=(x * x) + (y * y);
z=pow (z, 0.5);
}
main()
{
int x = 33, y = 44, z=0;
star (x, y, z);
cout< The value of x = "<< x << endl;
cout<<"The value of y="<< y << endl;
cout<<"The value of z="<<z<< endl; }

The value of x = 33
The value of y = 44
The value of z = 55

for number 3 and 4.


int star (int x, int sum)
{
if( x != 15)
{
if (x %2== 0) // for number 4.) if (x%2==1)
sum+=x;
cout<<sum<<endl;
star(x-1, sum); }
return 0; }
int main(){
int x=25;
3. ) star (x,25);

25
49
49
71
71
91
91
109
109
125
4. ) star (x,25);

50
50
73
73
94
94
113
113
130
130

V. Programming: (5 points each)


1. Write a program fragment to prompt the user to enter a number (2-dis it or more), the
computer will display the number reverse in order (e.g. input: 12345, output: 54321. note:
cursion only).

#include<iostream>
using namespace std;
int reverse(int y,int x)
{
if(x>0)
return reverse((y*10)+(x%10),x/10);
}
int main()
{
int x;
cin>>x;
cout<<reverse(0,x);
}

2. Write a program fragment to prompt the user to enter a number the computer will compute
and display all the values of each term in Fibonacci Sequence vertically. (Loop + Recursion).
//recursion lang ‘to
#include<iostream>
using namespace std;
int fibo(int x,int y,int z)
{
cout<<x<<endl;
if(z>1)
{
x=x+y;
y=x-y;
return fibo(x,y,z-1);
}
}
int main()
{
int x=1,y=0,z;
cin>>z;
fibo(x,y,z);
}

//Eto yung Loop + Recursion


#include<iostream>
using namespace std;
int fibo(int x)
{
if(x==0)
return 0;
else if(x==1)
return 1;
else
return fibo(x-1)+fibo(x-2);
}
int main()
{
int x;
cin>>x;
for(int i=1;i<=x;i++)
cout<<fibo(i)<<endl;
}

Optional: Trace the output (5 points)


int display (int x)
{
if(x=6) return 0;
else
cout<<x;
display(x+1); }
int main()
{ int x=1,y,z;
for(z=1; z<=5; z++){
y=display(x);
cout<<endl; }
return 0; }
12345
12345
12345
12345
12345

You might also like