Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/hello.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

int main(int argc, char *argv[]) {
// This is your first C program my friend
printf("Hello, RTU World from C Lab in 2025!\n");
printf("Hello, Professor my name is Edasu RTU World from C Lab in 2025!\n");
printf("You passed %d argument(s).\n", argc - 1);
for (int i = 1; i < argc; ++i) {
printf(" arg[%d] = %s\n", i, argv[i]);
Expand Down
32 changes: 19 additions & 13 deletions src/lab3_task1.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Lab 3, Task 1
* Student Name, Student ID
* Edasu Yadık, 231AEB028
*
* Implement array algorithms:
* - find minimum value
Expand Down Expand Up @@ -44,27 +44,33 @@ int main(void) {

// Implement functions below
int array_min(int arr[], int size) {
// TODO: return smallest element
int my_min = INT_MAX; //set to max infinity
for (int i=0;i<size;i++) {
if (my_min > arr[i]) {
int my_min = arr[0];
for (int i = 1; i < size; i++) {
if (arr[i] < my_min) {
my_min = arr[i];
}
}
return my_min; // placeholder
return my_min;
}

int array_max(int arr[], int size) {
// TODO: return largest element
return 0; // placeholder
int my_max = arr[0];
for (int i = 1; i < size; i++) {
if (arr[i] > my_max) {
my_max = arr[i];
}
}
return my_max;
}

int array_sum(int arr[], int size) {
// TODO: return sum of elements
return 0; // placeholder
int sum = 0;
for (int i = 0; i < size; i++) {
sum += arr[i];
}
return sum;
}

float array_avg(int arr[], int size) {
// TODO: return average as float
return 0.0f; // placeholder
int sum = array_sum(arr, size);
return (float) sum / size;
}
8 changes: 5 additions & 3 deletions src/lab3_task2.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Lab 3, Task 2
* Student Name, Student ID
* Edasu Yadık, 231AEB028
*
* Practice using pointers as function parameters.
* Implement:
Expand Down Expand Up @@ -38,9 +38,11 @@ int main(void) {

// Implement functions below
void swap(int *x, int *y) {
// TODO: swap values using a temporary variable
int temp = *x;
*x = *y;
*y = temp;
}

void modify_value(int *x) {
// TODO: multiply value by 2
*x = *x * 2;
}
18 changes: 14 additions & 4 deletions src/lab3_task3.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Lab 3, Task 3
* Student Name, Student ID
* Edasu Yadık, 231AEB028
*
* Implement basic string handling functions.
* Write your own versions of:
Expand Down Expand Up @@ -41,10 +41,20 @@ int main(void) {

// Implement functions below
int my_strlen(const char *str) {
// TODO: count characters until '\0'
return 0; // placeholder
int length = 0;
while (str[length] != '\0') {
length++;
}
return length;
}



void my_strcpy(char *dest, const char *src) {
// TODO: copy characters until '\0'
int i = 0;
while (src[i] != '\0') {
dest[i] = src[i];
i++;
}
dest[i] = '\0';
}