138 lines
2.5 KiB
C
138 lines
2.5 KiB
C
#include <stdio.h>
|
|
|
|
#include "p1.h"
|
|
#include "p2.h"
|
|
#include "p3.h"
|
|
#include "p4.h"
|
|
#include "p5.h"
|
|
#include "p6.h"
|
|
#include "p7.h"
|
|
#include "p8.h"
|
|
#include "p9.h"
|
|
#include "p10.h"
|
|
|
|
void print_int_arr(int* arr, int size) {
|
|
for (int i = 0; i < size; ++i) {
|
|
printf(" %d", arr[i]);
|
|
}
|
|
|
|
putchar('\n');
|
|
}
|
|
|
|
int main(void) {
|
|
// Problem 1
|
|
printf("Problem 1:\n");
|
|
double p1_arr[8] = {
|
|
2.5, 4.3, 8.1, -7.4, 2.0, 1.0, 3.0, 4.0
|
|
};
|
|
|
|
double avg = 0;
|
|
double min = 0;
|
|
double max = 0;
|
|
|
|
find_avg_min_max(p1_arr, 8, &avg, &min, &max);
|
|
|
|
printf("Average: %.2lf, Min: %.2lf, Max: %.2lf\n", avg, min, max);
|
|
|
|
// Problem 2
|
|
printf("Problem 2:\n");
|
|
int p2_arr[16] = { 1, 2, 3, 4, 5 };
|
|
int size = 5;
|
|
|
|
print_int_arr(p2_arr, size);
|
|
|
|
size = pop_front(p2_arr, size);
|
|
|
|
print_int_arr(p2_arr, size);
|
|
|
|
// Problem 3
|
|
printf("Problem 3:\n");
|
|
double sum_of_file = sum_file("input_p3.dat");
|
|
|
|
printf("Sum of file: %.2lf\n", sum_of_file);
|
|
|
|
// Problem 4
|
|
printf("Problem 4:\n");
|
|
int p4_value = prompt_value();
|
|
printf("You entered: %d\n", p4_value);
|
|
|
|
// Problem 5
|
|
printf("Problem 5:\n");
|
|
|
|
int num_alphanum = count_alphanumeric("Hello World!!");
|
|
printf("Number of alphanumeric characters in \"Hello World!!\": %d\n", num_alphanum);
|
|
|
|
// Problem 6
|
|
printf("Problem 6:\n");
|
|
|
|
char p6_str[32] = "I have 3$, wow!";
|
|
|
|
printf("\"%s\"\n", p6_str);
|
|
str_to_upper(p6_str);
|
|
printf("\"%s\"\n", p6_str);
|
|
|
|
// Problem 7
|
|
printf("Problem 7:\n");
|
|
|
|
char p7_str[32] = "Hello Exam #2!";
|
|
|
|
printf("\"%s\"\n", p7_str);
|
|
reverse_string(p7_str);
|
|
printf("\"%s\"\n", p7_str);
|
|
|
|
// Problem 8
|
|
printf("Problem 8:\n");
|
|
|
|
Student students[5];
|
|
|
|
for (int i = 0; i < 5; ++i) {
|
|
prompt_student_info(&students[i]);
|
|
}
|
|
|
|
for (int i = 0; i < 5; ++i) {
|
|
print_student(&students[i]);
|
|
}
|
|
|
|
double average_gpa = compute_average_gpa(students, 5);
|
|
|
|
printf("Average GPA: %.2lf\n", average_gpa);
|
|
|
|
// Problem 9
|
|
printf("Problem 9:\n");
|
|
|
|
Product products[4] = {
|
|
{ 4011, "Banana", 10.0, 1000 },
|
|
{ 412, "Apple", 2.5, 240 },
|
|
{ 728, "Pear", 4.8, 180 },
|
|
{ 119, "Orange", 1.6, 438 },
|
|
};
|
|
|
|
Product* found = find_product(products, 4, 728);
|
|
|
|
if (found != NULL) {
|
|
printf("Found product \"%s\" with id %d\n", found->name, found->id);
|
|
} else {
|
|
printf("Did not find any matching products!\n");
|
|
}
|
|
|
|
// Problem 10
|
|
printf("Problem 10:\n");
|
|
|
|
double vectors[3][8] = {
|
|
{ 1, 2, 3, 4, 5, 6, 7, 8 },
|
|
{ 0, 0, 0, 0, 0, 5, 0, 0 },
|
|
{ 1, 1, 1, 1, 1, 1, 1, 1 },
|
|
};
|
|
|
|
double magnitudes[3] = { 0 };
|
|
|
|
calculate_magnitudes(vectors, 3, magnitudes);
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
|
printf("magnitude %d: %.2lf\n", i, magnitudes[i]);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|