Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

\\ COMPUTER PROBLEM 3.

#include <iostream> - to declare operations – if missing ni you will be having an error in using cout, cin,
endl. Declaration is important to specify data types of variables, operations and funcions.
using namespace std; - When you include using namespace std, you are telling the compiler that you want to use all the
symbols (such as classes, functions, and variables) defined in the std namespace without specifying the namespace
explicitly.

int main() { - This line marks the beginning of the main function, which is the starting point of the program. The int before
main() specifies that the function will return an integer value.

const int maxSize = 10; - The line const int maxSize = 10; is a declaration in C++ that defines a constant integer variable
named maxSize with a value of 10.
int numbers[maxSize]; - This line declares an integer array named numbers with a size equal to the value of the maxSize
constant. In this case, since you've defined maxSize as 10 (const int maxSize = 10;), the array numbers will have a size of 10.
This means it can hold 10 integer values.
int count = 0; - declare an integer “count” with an initial value of zero. Count is used po to tract elements that are
currently stored po in the “numbers”

cout<< "SUBMITTED BY: \t\tEmanuel Laurence Montes\n" – short for character output. To output text or data to
the console
<< "\t\t\tFrancis Rance\n"
<< "\t\t\tLorejean Flor\n\n\n"
<< "Enter up to 10 positive numbers (enter a negative number to stop):" << endl;

// Read input until a negative number is entered or the array is full

while (count < maxSize) { - while loop continue untiil “count” values is less that the “maxsize”
int num; - using this inside the loop to declare that the input values are stored in “num”
cin >> num; - we use cin here to read the user input and assign it to the “num” variable.

if (num < 0) { - here we put a condition that if the entered number is less than zero then the “break” statement will be
executed, which means it will exit the loop
break; // Stop input when a negative number is entered – basically this part is created to control the user input and
and limit the numbers of input in the program.
}

numbers[count] = num; - to collect positive integer inputs and store them in “numbers” while still keeping tract of the
counts of inputs entered.
count++;
}

cout << "Numbers in reverse order:" << endl;

// Print the numbers in reverse order


for (int i = count - 1; i >= 0; i--) { - for loop that sets I to count 1- which count represents the positive integers being
entered by the user. So the loop continues as long as I is greater than 1.
cout << numbers[i] << " "; - we use cout to output the values stored in the “numbers” indicated by i. since I is one then
count -1, the loop starts from the last element array and works its way backward.
} // it closes the main function of the preceeding loop.

cout << endl; //to declare another line of output.

return 0; // to signal successful completion of program with an exit status of 0.


}
COMPUTER PROBLEM 1
#include <iostream> ------ Declare operations
#include <stdio.h> ------short for standard input and output needs to be declared to carry out input/output operations.
“stdio.h” contains also features such as printf() or function for formatted output.
using namespace std; ------

int main() {
int num;
int sum = 0;
back:
cout<< "Emanuel Laurence Montes\n"
<< "Francis Rance\n"
<< "Lorejean Flor\n\n\n"
<< "Enter a positive integer: ";
scanf("%d", &num); //inorder to read the user. The “%d here if for the integers that was declared.
cout<<endl;

if (num <= 0) { //if the number entered is less than or equal to 0 then maghatag ug warning to input positive integers.
cout << "Please enter a positive integer." << endl;
system ("pause"); //if not kay ma execute ang pause command. It will make the screen to wait for a key to press.
Then mabalik nasad siya mangayo nasad siya ug positive integer.
system ("cls");
goto back;
}
else {
for (int i = 1; i <= num; i++) {
sum = sum+(i * i);
if (i!=num)
printf("%d^2 + ",i);
else
printf("%d^2 = %d",i,sum);
}
}
return 0;
}

You might also like