-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
21e50d8
commit 1128035
Showing
5 changed files
with
170 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,17 @@ | ||
#include <stdio.h> | ||
|
||
void print_array(int *array, int size) | ||
{ | ||
for (int i = size - 1; i >= 0; i--) | ||
{ | ||
printf("%d ", *(array + i)); | ||
} | ||
printf("\n"); | ||
} | ||
|
||
int main() | ||
{ | ||
|
||
int array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}; | ||
print_array(array, 10); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include <stdio.h> | ||
#include <math.h> | ||
|
||
void calculate_roots(float a, float b, float c, float *x1, float *x2) | ||
{ | ||
float discriminant = b * b - 4 * a * c; | ||
if (discriminant < 0) | ||
{ | ||
*x1 = *x2 = 0; | ||
} | ||
else if (discriminant == 0) | ||
{ | ||
*x1 = *x2 = -b / (2 * a); | ||
} | ||
else | ||
{ | ||
*x1 = (-b + sqrt(discriminant)) / (2 * a); | ||
*x2 = (-b - sqrt(discriminant)) / (2 * a); | ||
} | ||
} | ||
|
||
int main() | ||
{ | ||
float a, b, c, x1, x2; | ||
printf("Enter a, b, c: "); | ||
scanf("%f %f %f", &a, &b, &c); | ||
calculate_roots(a, b, c, &x1, &x2); | ||
printf("x1 = %f, x2 = %f\n", x1, x2); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <stdio.h> | ||
|
||
void fill_array(int *array, int size, int value) | ||
{ | ||
int temp; | ||
int i; | ||
for (i = 0; i < size; i++) | ||
{ | ||
if ( array[i] > value ) | ||
{ | ||
temp = array[i]; | ||
array[i] = value; | ||
break; | ||
} | ||
} | ||
for (i = i + 1; i < size; i++) | ||
{ | ||
int temp2 = array[i]; | ||
array[i] = temp; | ||
temp = temp2; | ||
} | ||
|
||
} | ||
|
||
int main() | ||
{ | ||
int array[10] = {1, 2, 3, 5, 6, 7, 8}; | ||
int remaining = 4; | ||
|
||
fill_array(array, 10, remaining); | ||
for (int i = 0; i < 10; i++) | ||
{ | ||
printf("%d ", array[i]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#include <stdio.h> | ||
|
||
void matrix_addition(int *matrix_one, int *matrix_two, int row, int col, int *matrix_sum) | ||
{ | ||
for (int i = 0; i < row; i++) | ||
{ | ||
for (int j = 0; j < col; j++) | ||
{ | ||
*(matrix_sum + i * col + j ) = *(matrix_one + i * col + j) + *(matrix_two + i * col + j); | ||
} | ||
} | ||
return; | ||
} | ||
|
||
int main() | ||
{ | ||
int row, col; | ||
printf("Enter row and column: "); | ||
scanf("%d %d", &row, &col); | ||
|
||
int matrix_one[row][col]; | ||
int matrix_two[row][col]; | ||
|
||
printf("Row: %d, Col: %d\n", row, col); | ||
|
||
printf("Enter elements of the first matrix:\n"); | ||
for (int i = 0 ; i < row; i++) | ||
{ | ||
for (int j = 0; j < col; j++) | ||
{ | ||
scanf("%d", &matrix_one[i][j]); | ||
} | ||
} | ||
|
||
printf("Enter elements of the second matrix:\n"); | ||
for (int i = 0 ; i < row; i++) | ||
{ | ||
for (int j = 0; j < col; j++) | ||
{ | ||
scanf("%d", &matrix_two[i][j]); | ||
} | ||
} | ||
|
||
int matrix_sum[row][col]; | ||
matrix_addition((int *)matrix_one, (int *)matrix_two, row, col, (int *)matrix_sum); | ||
|
||
printf("Sum of the two matrices:\n"); | ||
for (int i = 0 ; i < row; i++) | ||
{ | ||
for (int j = 0; j < col; j++) | ||
{ | ||
printf("%d ", matrix_sum[i][j]); | ||
} | ||
printf("\n"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include <stdio.h> | ||
|
||
void remove_character(char *string, char what_to_remove) | ||
{ | ||
int i = 0; | ||
while (string[i] != '\0') | ||
{ | ||
if (string[i] == what_to_remove) | ||
{ | ||
int j = i; | ||
while (string[j] != '\0') | ||
{ | ||
string[j] = string[j + 1]; | ||
j++; | ||
} | ||
} | ||
else | ||
{ | ||
i++; | ||
} | ||
} | ||
} | ||
|
||
int main() | ||
{ | ||
char string[100]; | ||
char what_to_remove; | ||
|
||
printf("Enter a string: "); | ||
scanf("%s", string); | ||
|
||
printf("Enter a character to remove: "); | ||
scanf(" %c", &what_to_remove); | ||
|
||
remove_character(string, what_to_remove); | ||
|
||
printf("Result: %s\n", string); | ||
} |