Skip to content
3 changes: 2 additions & 1 deletion src/hello.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

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 from Murad! \n");
printf("Hello, 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
Binary file added src/lab2_1
Binary file not shown.
24 changes: 17 additions & 7 deletions src/lab2_1.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Name : Murad Hashimov , id : 241ADB148
#include <stdio.h>

/*
Expand All @@ -12,17 +13,26 @@
*/

int sum_to_n(int n) {
// TODO: implement sum with a for loop
return 0; // placeholder
int inp = 0;
for (int i = 1; i <= n; i++) {
inp = inp + i;
}
return inp; // placeholder
}

int main(void) {
int n;
int n;

printf("Enter a positive integer n: ");
scanf("%d", &n);
printf("Enter a positive integer n: ");
scanf("%d", &n);
if (n < 1) {
printf("Error");
} else {
int result = sum_to_n(n);
printf("Result %d\n", result);
}

// TODO: validate input, call function, and print result
// TODO: validate input, call function, and print result

return 0;
return 0;
}
Binary file added src/lab2_2
Binary file not shown.
29 changes: 22 additions & 7 deletions src/lab2_2.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Name : Murad Hashimov , id : 241ADB148

#include <stdio.h>

/*
Expand All @@ -12,17 +14,30 @@
*/

long long factorial(int n) {
// TODO: compute factorial iteratively
return 1; // placeholder
int a = 1;
int res = 1;

while (a <= n) {
res = res * a;
a++;
}
return res; // placeholder
}

int main(void) {
int n;
int n;

printf("Enter a non-negative integer n: ");
scanf("%d", &n);

printf("Enter a non-negative integer n: ");
scanf("%d", &n);
if (n < 0) {
printf("Error , cause it is negative");
} else {
int res = factorial(n);
printf("Factorial of %d is %d", n, res);
}

// TODO: validate input, call function, print result
// TODO: validate input, call function, print result

return 0;
return 0;
}
30 changes: 22 additions & 8 deletions src/lab2_3.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Name : Murad Hashimov , id : 241ADB148

#include <math.h>
#include <stdio.h>

/*
Expand All @@ -12,17 +15,28 @@
*/

int is_prime(int n) {
// TODO: check if n is prime using loop up to sqrt(n)
return 0; // placeholder
for (int i = 2; i <= sqrt(n); i++) {
if (n % i == 0) return 0;
}

return 1;
}

int main(void) {
int n;

printf("Enter an integer n (>= 2): ");
scanf("%d", &n);
int n;

// TODO: validate input and print all primes up to n
printf("Enter an integer n (>= 2): ");
scanf("%d", &n);

return 0;
if (n < 2) {
printf("Error");
} else {
printf("Prime numbers - %d are:\n", n);
for (int i = 2; i <= n; i++) {
if (is_prime(i)) {
printf("%d ", i);
}
}
}
return 0;
}
Binary file added src/lab3_task1
Binary file not shown.
55 changes: 33 additions & 22 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
* Murad Hashimov, 241ADB148
*
* Implement array algorithms:
* - find minimum value
Expand All @@ -21,8 +21,8 @@
* avg = array_avg(arr, 5); // 3.0
*/

#include <stdio.h>
#include <limits.h>
#include <stdio.h>

// Function prototypes
int array_min(int arr[], int size);
Expand All @@ -31,40 +31,51 @@ int array_sum(int arr[], int size);
float array_avg(int arr[], int size);

int main(void) {
int arr[] = {10, 20, 5, 30, 15};
int size = 5;
int arr[] = {10, 20, 5, 30, 15};
int size = 5;

printf("Min: %d\n", array_min(arr, size));
printf("Max: %d\n", array_max(arr, size));
printf("Sum: %d\n", array_sum(arr, size));
printf("Avg: %.2f\n", array_avg(arr, size));
printf("Min: %d\n", array_min(arr, size));
printf("Max: %d\n", array_max(arr, size));
printf("Sum: %d\n", array_sum(arr, size));
printf("Avg: %.2f\n", array_avg(arr, size));

return 0;
return 0;
}

// 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]) {
my_min = arr[i];
}
int my_min = INT_MAX;
for (int i = 1; i < size; i++) {
if (arr[i] < my_min) {
my_min = arr[i];
}
return my_min; // placeholder
}
return my_min; // placeholder
}

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

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

float array_avg(int arr[], int size) {
// TODO: return average as float
return 0.0f; // placeholder
float my_sum = 0.0;
for (int i = 0; i < size; i++) {
my_sum = my_sum + arr[i];
}
float my_avg = my_sum / size;
return my_avg; // placeholder
}
Binary file added src/lab3_task2
Binary file not shown.
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
* Murad Hashimov, 241ADB148
*
* 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 val = *x;
*x = *y;
*y = val;
}

void modify_value(int *x) {
// TODO: multiply value by 2
*x = (*x)*2;
}
Binary file added src/lab3_task3
Binary file not shown.
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
* Murad Hashimov, 241ADB148
*
* 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 size = 0;
while(str[size] != '\0'){
size = size + 1;
}
return size; // placeholder
}

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

dest[val] = src[val];

val++;
}
dest[val] = '\0';
}
2 changes: 2 additions & 0 deletions src/rfse.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Vote for Murad Hashimov!
RTU is top G
3 changes: 3 additions & 0 deletions src/student.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Alice
21
3.75
2 changes: 2 additions & 0 deletions src/students.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
2425 Murad
4.500000
Binary file added src/week4_1_dynamic_array
Binary file not shown.
27 changes: 24 additions & 3 deletions src/week4_1_dynamic_array.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* week4_1_dynamic_array.c
* Author: [Your Name]
* Student ID: [Your ID]
* Author: [Murad Hashimov]
* Student ID: [241ADB148]
* Description:
* Demonstrates creation and usage of a dynamic array using malloc.
* Students should allocate memory for an integer array, fill it with data,
Expand All @@ -12,6 +12,7 @@
#include <stdlib.h>

int main(void) {
int summ;
int n;
int *arr = NULL;

Expand All @@ -22,17 +23,37 @@ int main(void) {
}

// TODO: Allocate memory for n integers using malloc
arr = malloc(n * sizeof(int));
// Example: arr = malloc(n * sizeof(int));

// TODO: Check allocation success
if (arr == 0) {
printf("\nMemory allocation is false!");
return 1;
}

// TODO: Read n integers from user input and store in array

printf("Put %d integers into array - \n", n);
for (int i = 0; i < n; i++) {
if (scanf("%d", &arr[i]) != 1) {
printf("Invalid input.\n");
free(arr);
return 1;
}
}
// TODO: Compute sum and average
for (int i = 0; i < n; i++) {
summ = summ + arr[i];
}
float average = (float)summ / n;

// TODO: Print the results
printf("The sum of values - %d \n", summ);

printf("The average of values - %f \n", average);

// TODO: Free allocated memory
free(arr);

return 0;
}
Binary file added src/week4_2_struct_student
Binary file not shown.
32 changes: 23 additions & 9 deletions src/week4_2_struct_student.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* week4_2_struct_student.c
* Author: [Your Name]
* Student ID: [Your ID]
* Author: [Murad Hashimov]
* Student ID: [241ADB148]
* Description:
* Demonstrates defining and using a struct in C.
* Students should define a 'Student' struct with fields like name, id, and grade.
Expand All @@ -13,18 +13,32 @@

// TODO: Define struct Student with fields: name (char[]), id (int), grade (float)
// Example:
// struct Student {
// char name[50];
// int id;
// float grade;
// };
struct Student {
char name[50];
int id;
float grade;
};

int main(void) {
struct Student student_1;

struct Student student_2;

// TODO: Declare one or more Student variables
strcpy(student_1.name, "Murad Hashimov");
student_1.id = 241148;
student_1.grade = 80.0;

// TODO: Assign values (either manually or via scanf)
// student_2
strcpy(student_2.name, "Bombo Clad");
student_2.id = 241567;
student_2.grade = 95;

// TODO: Print struct contents using printf

printf("Student 1: Name: %s\n, ID: %d\n, Grade: %f\n", student_1.name, student_1.id, student_1.grade);
//
printf("Student 2: Name: %s\n, ID: %d\n, Grade: %f\n", student_2.name, student_2.id, student_2.grade);


return 0;
}
Binary file added src/week4_3_struct_database
Binary file not shown.
Loading