RAFAEL THEO N.
RAMENTO
CE2-5
ACTIVITY 5.5 LOOP CONTROL STRUCTURE
1)
#include <stdio.h>
int main() {
char studentName[100];
char section[100];
int n, i, arr[100], max, min, sum = 0;
printf("Enter Student Name: ");
fgets(studentName, sizeof(studentName), stdin);
printf("Enter Section: ");
fgets(section, sizeof(section), stdin);
printf("Enter the count of numbers to be entered: ");
scanf("%d", &n);
printf("\nStudent Name: %s", studentName);
printf("Section: %s", section);
printf("Enter Numbers\n ");
for(i = 0; i < n; i++) {
scanf("%d", &arr[i]);
max = arr[0];
min = arr[0];
i = 0;
while(i < n) {
sum = sum + arr[i];
if(arr[i] > max) {
max = arr[i];
if(arr[i] < min) {
min = arr[i];
i++;
printf("\nThe Highest number is: %d", max);
printf("\nThe Smallest number is: %d", min);
printf("\nSum of all elements is %d", sum);
return 0;
}
2)
#include <stdio.h>
int gcd(int a, int b) {
if (b == 0) {
return a;
} else {
return gcd(b, a % b);
int main() {
char studentName[100];
char section[100];
int num1, num2;
char choice;
do {
printf("Enter Student Name: ");
fgets(studentName, sizeof(studentName), stdin);
printf("Enter Section: ");
fgets(section, sizeof(section), stdin);
printf("Enter the value of first number: ");
scanf("%d", &num1);
printf("Enter the value of second number: ");
scanf("%d", &num2);
printf("\nStudent Name: %s", studentName);
printf("Section: %s\n", section);
int result = gcd(num1, num2);
printf("The Greatest Common Divisor of %d and %d is %d\n", num1, num2, result);
printf("\nType Y/y if you want to try again. Type N/n to exit: ");
scanf(" %c", &choice);
while (getchar() != '\n'); // Clear input buffer
} while (choice == 'Y' || choice == 'y');
return 0;
}
3)
#include <stdio.h>
int main() {
char studentName[100];
char section[100];
int numbers[10];
int i, evenSum = 0, oddSum = 0, totalSum = 0;
printf("Student Name: ");
fgets(studentName, sizeof(studentName), stdin);
printf("Section: ");
fgets(section, sizeof(section), stdin);
printf("Enter 10 Numbers: ");
for (i = 0; i < 10; i++) {
scanf("%d", &numbers[i]);
if (numbers[i] % 2 == 0) {
evenSum += numbers[i];
} else {
oddSum += numbers[i];
totalSum += numbers[i];
printf("\n------------------------------\n");
printf("%s", studentName);
printf("%s", section);
printf("--------------------------------\n");
printf("Even Numbers: ");
for (i = 0; i < 10; i++) {
if (numbers[i] % 2 == 0) {
printf("%d, ", numbers[i]);
}
printf("\nTotal: %d\n", evenSum);
printf("--------------------------------\n");
printf("Odd Numbers: ");
for (i = 0; i < 10; i++) {
if (numbers[i] % 2 != 0) {
printf("%d, ", numbers[i]);
printf("\nTotal: %d\n", oddSum);
printf("-------------------------------\n");
printf("Numbers:\n");
for (i = 0; i < 10; i++) {
printf("%8d\n", numbers[i]);
printf("Total: %d\n", totalSum);
return 0;