Reorder problems
This commit is contained in:
parent
2faea7bcfb
commit
7c56902d6d
@ -1,7 +1,8 @@
|
||||
#ifndef P1_H
|
||||
#define P1_H
|
||||
#ifndef P2_H
|
||||
#define P2_H
|
||||
|
||||
int count_alphanumeric(const char* str);
|
||||
void find_avg_min_max(double* arr, int size,
|
||||
double* out_avg, double* out_min, double* out_max);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@ -1,8 +0,0 @@
|
||||
#ifndef P2_H
|
||||
#define P2_H
|
||||
|
||||
void find_avg_min_max(double* arr, int size,
|
||||
double* out_avg, double* out_min, double* out_max);
|
||||
|
||||
#endif
|
||||
|
||||
7
include/p5.h
Normal file
7
include/p5.h
Normal file
@ -0,0 +1,7 @@
|
||||
#ifndef P1_H
|
||||
#define P1_H
|
||||
|
||||
int count_alphanumeric(const char* str);
|
||||
|
||||
#endif
|
||||
|
||||
41
src/p1.c
41
src/p1.c
@ -1,19 +1,32 @@
|
||||
#include "p1.h"
|
||||
#include "p2.h"
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
int count_alphanumeric(const char* str) {
|
||||
int num_alphanumeric = 0;
|
||||
const char* current = str;
|
||||
|
||||
while (*current != '\0') {
|
||||
if (isalnum(*current)) {
|
||||
++num_alphanumeric;
|
||||
}
|
||||
|
||||
++current;
|
||||
void find_avg_min_max(double* arr, int size,
|
||||
double* out_avg, double* out_min, double* out_max) {
|
||||
// If there are no elements in the array, attempting to access the first
|
||||
// element to initialize min and max will access memory outside the bounds
|
||||
// of the array. Instead, we will return early.
|
||||
if (size <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
return num_alphanumeric;
|
||||
double sum = 0;
|
||||
double min = arr[0];
|
||||
double max = arr[0];
|
||||
|
||||
for (int i = 0; i < size; ++i) {
|
||||
sum += arr[i];
|
||||
|
||||
if (arr[i] < min) {
|
||||
min = arr[i];
|
||||
}
|
||||
|
||||
if (arr[i] > max) {
|
||||
max = arr[i];
|
||||
}
|
||||
}
|
||||
|
||||
*out_avg = sum / size;
|
||||
*out_min = min;
|
||||
*out_max = max;
|
||||
}
|
||||
|
||||
|
||||
32
src/p2.c
32
src/p2.c
@ -1,32 +0,0 @@
|
||||
#include "p2.h"
|
||||
|
||||
void find_avg_min_max(double* arr, int size,
|
||||
double* out_avg, double* out_min, double* out_max) {
|
||||
// If there are no elements in the array, attempting to access the first
|
||||
// element to initialize min and max will access memory outside the bounds
|
||||
// of the array. Instead, we will return early.
|
||||
if (size <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
double sum = 0;
|
||||
double min = arr[0];
|
||||
double max = arr[0];
|
||||
|
||||
for (int i = 0; i < size; ++i) {
|
||||
sum += arr[i];
|
||||
|
||||
if (arr[i] < min) {
|
||||
min = arr[i];
|
||||
}
|
||||
|
||||
if (arr[i] > max) {
|
||||
max = arr[i];
|
||||
}
|
||||
}
|
||||
|
||||
*out_avg = sum / size;
|
||||
*out_min = min;
|
||||
*out_max = max;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user