OS (HandsOn Act Finals)
OS (HandsOn Act Finals)
Write a function-oriented program that will compute the sum of the sequence
numbers from 1 to N where N is a supplied value by the user.
#include <stdio.h>
int calculate_sum(int N) {
int sum = 0;
for (int i = 1; i <= N; i++) {
sum += i;
}
return sum;
}
int main() {
int N;
printf("Enter a number N: ");
scanf("%d", &N);
if (N <= 0) {
printf("Please enter a positive number.\n");
} else {
int result = calculate_sum(N);
printf("The sum of numbers from 1 to %d is: %d\n", N, result);
}
return 0;
}
2. Write a function-oriented program that computes the total of the squares from 1
to N supplied by the user.
#include <stdio.h>
int calculate_square_sum(int N) {
int sum = 0;
for (int i = 1; i <= N; i++) {
sum += i * i;
}
return sum;
}
int main() {
int N;
printf("Enter a number N: ");
scanf("%d", &N);
if (N <= 0) {
printf("Please enter a positive number.\n");
} else {
int result = calculate_square_sum(N);
printf("The sum of squares from 1 to %d is: %d\n", N, result);
}
return 0;
}
3. Write a function-oriented program to compute the area of the circle. Use this
formula
#include <stdio.h>
#define PI 3.1415
double calculate_area(double r) {
return PI * r * r;
}
int main() {
double r;
printf("Enter the radius of the circle: ");
scanf("%lf", &r);
if (r <= 0) {
printf("Please enter a positive radius.\n");
} else {
double area = calculate_area(r);
printf("The area of the circle with radius %.2lf is: %.2lf\n", r, area);
}
return 0;
}
4. Write a function-oriented program that will ask the user to give five numbers
and then the program will compute the sum of the five numbers.
#include <stdio.h>
int calculate_sum(int num1, int num2, int num3, int num4, int num5) {
return num1 + num2 + num3 + num4 + num5;
}
int main() {
int num1, num2, num3, num4, num5;
return 0;
}
5. Write a function-oriented program that will convert the input inches to its
centimeter equivalent. 1 inch equals to 2.4 cms. Display the converted centimeters
values.
#include <stdio.h>
int main() {
float inches;
return 0;
}
6. Write a function-oriented program that will ask the user to give two numbers and
then the program will solve the sum, product, difference and quotient, and display
the result on the screen.
#include <stdio.h>
int main() {
double num1, num2;
printf("\nResults:\n");
printf("Sum: %.2lf\n", sum);
printf("Product: %.2lf\n", product);
printf("Difference: %.2lf\n", difference);
if (num2 != 0) {
printf("Quotient: %.2lf\n", quotient);
}
return 0;
}
#include <stdio.h>
int main() {
double base;
int exponent;
return 0;
}
8. Write a function-oriented program that will convert the input US Dollar (S)
value into its equivalent in Philippine Peso (PHP). Let us assume that one dollar
is equivalent to PHP 55.65 pesos.
#include <stdio.h>
int main() {
double usd;
return 0;
}
9. Write a function-oriented program that will ask the user to give a number and
then the program will check if the given number is an odd or even number and
display the result on the screen.
#include <stdio.h>
int main() {
int number;
check_odd_or_even(number);
return 0;
}
10. Write a function-oriented program that will ask the user to give a year and
then the program will determine if the given year by the user is a leap year or not
a leap year and display the result on the screen.
#include <stdio.h>
int main() {
int year;
if (is_leap_year(year)) {
printf("%d is a leap year.\n", year);
} else {
printf("%d is not a leap year.\n", year);
}
return 0;
}