0% found this document useful (0 votes)
23 views

Lab2 Programming

The document provides 5 programming exercises: 1) a program that reads two integers and calculates their mathematical operations. 2) a program that compares two integers and displays the larger or if equal. 3) a program that determines if an integer is odd or even. 4) a program that determines if one integer is a multiple of another. 5) a program that calculates the squares and cubes of the numbers 0 through 10 in a table.

Uploaded by

bryankachocho17
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Lab2 Programming

The document provides 5 programming exercises: 1) a program that reads two integers and calculates their mathematical operations. 2) a program that compares two integers and displays the larger or if equal. 3) a program that determines if an integer is odd or even. 4) a program that determines if one integer is a multiple of another. 5) a program that calculates the squares and cubes of the numbers 0 through 10 in a table.

Uploaded by

bryankachocho17
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

DR_BRILLIANT

LAB2 PROCEDURE PROGRAMMING EXERCISE

1. Write a program that reads two integers from the user then displays their sum, product,
difference, quotient and remainder

#include <stdio.h>

int main() {

int num1, num2;

printf("Enter the first integer: ");

scanf("%d", &num1);

printf("Enter the second integer: ");

scanf("%d", &num2);

int sum = num1 + num2;

int product = num1 * num2;

int difference = num1 - num2;

int quotient = num1 / num2;

int remainder = num1 % num2;

printf("Sum: %d\n", sum);

printf("Product: %d\n", product);

printf("Difference: %d\n", difference);

printf("Quotient: %d\n", quotient);

printf("Remainder: %d\n", remainder);

return 0;

}
2. Write a program that reads two integers from the user then displays the larger number
followed by the words “is larger.” If the numbers are equal, display the message “These
numbers are equal.” Use only the single-selection form of the if statement.
#include <stdio.h>

int main() {
int num1, num2;

printf("Enter the first integer: ");


scanf("%d", &num1);

printf("Enter the second integer: ");


scanf("%d", &num2);

if (num1 > num2) {


printf("%d is larger.\n", num1);
} else if (num2 > num1) {
printf("%d is larger.\n", num2);
} else {
printf("These numbers are equal.\n");
}

return 0;
}

3. Write a program that reads an integer and determines and displays whether it’s odd or even.
Use the remainder operator. An even number is a multiple of two. Any multiple of two leaves
a remainder of zero when divided by 2.
#include <stdio.h>

int main() {
int number;

printf("Enter an integer: ");


scanf("%d", &number);

if (number % 2 == 0) {
printf("%d is even.\n", number);
} else {
printf("%d is odd.\n", number);
}

return 0;
}
4. Write a program that reads two integers and determines and displays whether the first is a
multiple of the second. Use the remainder operator

#include <stdio.h>

int main() {

int num1, num2;

printf("Enter the first integer: ");

scanf("%d", &num1);

printf("Enter the second integer: ");

scanf("%d", &num2);

if (num1 % num2 == 0) {

printf("%d is a multiple of %d.\n", num1, num2);

} else {

printf("%d is not a multiple of %d.\n", num1, num2);

return 0;

5.Using only the techniques you learned in Lecture ii, write a program that calculates the squares
and cubes of the numbers from 0 to 10 and uses tabs to display the following table of values:

#include <stdio.h>

int main() {

int number;

printf("Number\tSquare\tCube\n");
for (number = 0; number <= 10; number++) {

int square = number * number;

int cube = number * number * number;

printf("%d\t%d\t%d\n", number, square, cube);

return 0;

You might also like