You are on page 1of 3

UNIVERSITY OF SCIENCE AND TECHNOLOGY

OF SOUTHERN PHILIPPINES
Alubijid | Cagayan de Oro | Claveria | Jasaan | Oroquieta | Panaon

IT112 - Computer Programming 1


Activity 7

Name: Bercede, Raffy O.


Section: IT1R13

I. OUTPUT GENERATION EXERCISE. READ THE INSTRUCTIONS CAREFULLY.

With the code below, try to be the compiler and run the program. Try to figure out the output by reading the code
provided. Write your predicted output and after you have predicted the output, encode the same code in a compiler and
run the program. Check and compare if your predicted output is the same with the output generated by the compiler.

Answer:

#include<iostream>;
using namespace std;

int display();
int num;

int main() {

cout << "Please Enter a Number: ";


cin >> ::num;
display();
}
int display(){
}
for (int i = num; i >= 1; --i){

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

cout << "X";


}
cout << endl;
}
}

II. ACTIVITY PROPER. FUNCTION CREATION EXERCISES.

1. Create a program that will generate a reverse series of numbers depending on the value given by the
user. Your program should ask for a number from the user. If the user gives 10, your program should
output 10, 9, 8, 7, 6, 5, 4, 3, 2, 1. The generation of the number series will be done by a function.

#include<iostream>;
UNIVERSITY OF SCIENCE AND TECHNOLOGY
OF SOUTHERN PHILIPPINES
Alubijid | Cagayan de Oro | Claveria | Jasaan | Oroquieta | Panaon

using namespace std;

int reverse();
int value;

int main() {
cout << "Please Enter a Value: ";
cin >> ::value;
reverse();
}

int reverse(){

for (int i = value; i >= 1; --i){

cout << i;
cout << endl;
}
}

2. Create a program where it will check whether the number given by the user is odd or even.
Determination of the number whether it is odd or even will be done inside a user defined function.

#include <iostream>
using namespace std;

int num;
int check();

int main() {
cout << "Enter a Number: ";
cin >> ::num;
check();
}
int check() {
int sum;

sum = ::num % 2;

if (!sum) {

cout << "Number is an even number.";

} else if (sum) {

cout << "Number is an odd number.";


}
}
UNIVERSITY OF SCIENCE AND TECHNOLOGY
OF SOUTHERN PHILIPPINES
Alubijid | Cagayan de Oro | Claveria | Jasaan | Oroquieta | Panaon

You might also like