-
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.
Merge branch 'SharafatKarim:main' into main
- Loading branch information
Showing
31 changed files
with
1,435 additions
and
154 deletions.
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
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,4 +1,4 @@ | ||
#include <stdio.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <math.h> | ||
|
||
|
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,18 @@ | ||
#include<stdio.h> | ||
|
||
int a = 10, b = 20; | ||
|
||
void swap (void) | ||
{ | ||
b = a + b ; | ||
a = b - a ; | ||
b = b - a ; | ||
} | ||
|
||
int main() | ||
{ | ||
printf("Before swap: a = %d, b = %d\n", a, b); | ||
swap(); | ||
printf("After swap: a = %d, b = %d\n", a, b); | ||
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,44 @@ | ||
#include <stdio.h> | ||
#include <math.h> | ||
|
||
float perimeter(float a, float b, float c) | ||
{ | ||
return a + b + c; | ||
} | ||
|
||
float area(float a, float b, float c) | ||
{ | ||
float s = (a + b + c) / 2; | ||
return sqrt((s - a) * (s - b) * (s - c)); | ||
} | ||
|
||
int main() | ||
{ | ||
float a, b, c; | ||
char operation; | ||
|
||
printf("Enter first side: "); | ||
scanf("%f", &a); | ||
printf("Enter second side: "); | ||
scanf("%f", &b); | ||
printf("Enter third side: "); | ||
scanf("%f", &c); | ||
|
||
printf("Enter one of the followings: "); | ||
printf("\n(a) Perimeter of the triangle "); | ||
printf("\n(b) Area of the triangle "); | ||
printf("\n"); | ||
|
||
scanf(" %c", &operation); | ||
switch (operation) | ||
{ | ||
case 'a': | ||
printf("Result -> %f\n", perimeter(a, b, c)); | ||
break; | ||
case 'b': | ||
printf("Result -> %f\n", area(a, b, c)); | ||
break; | ||
default: | ||
printf("Invalid operation\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,32 @@ | ||
#include <stdio.h> | ||
|
||
int find_largest(int *matrix, int rows, int cols) { | ||
int i, j, largest = *matrix; | ||
for (i = 0; i < rows; i++) { | ||
for (j = 0; j < cols; j++) { | ||
if (*(matrix + i * cols + j) > largest) { | ||
largest = *(matrix + i * cols + j); | ||
} | ||
} | ||
} | ||
return largest; | ||
} | ||
|
||
int main() { | ||
int m, n, i, j; | ||
printf("Enter number of rows and columns: "); | ||
scanf("%d %d", &m, &n); | ||
|
||
int matrix[m][n]; | ||
printf("Enter matrix elements: \n"); | ||
for (i = 0; i < m; i++) { | ||
for (j = 0; j < n; j++) { | ||
scanf("%d", &matrix[i][j]); | ||
} | ||
} | ||
|
||
int largest = find_largest(&matrix[0][0], m, n); | ||
printf("Largest element in the matrix is %d\n", largest); | ||
|
||
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,64 @@ | ||
#include <stdio.h> | ||
|
||
void multiply_matrices(int *matrix_one, int *matrix_two, int m, int n) | ||
{ | ||
int i, j, k; | ||
int result[m][m]; | ||
|
||
for (i = 0; i < m; i++) | ||
{ | ||
for (j = 0; j < m; j++) | ||
{ | ||
|
||
result[i][j] = 0; | ||
for (k = 0; k < n; k++) | ||
{ | ||
result[i][j] += *(matrix_one + i * n + k) * *(matrix_two + k * m + j); | ||
} | ||
} | ||
} | ||
|
||
printf("Resultant matrix: \n"); | ||
for (i = 0; i < m; i++) | ||
{ | ||
printf("["); | ||
for (j = 0; j < m; j++) | ||
{ | ||
printf(" %d ", result[i][j]); | ||
} | ||
printf("]\n"); | ||
} | ||
} | ||
|
||
int main() | ||
{ | ||
int m, n; | ||
printf("Enter m and n (mxn) (nxm): "); | ||
scanf("%d %d", &m, &n); | ||
|
||
int matrix_one[m][n]; | ||
int matrix_two[n][m]; | ||
int i, j; | ||
|
||
printf("Enter matrix one elements: \n"); | ||
for (i = 0; i < m; i++) | ||
{ | ||
for (j = 0; j < n; j++) | ||
{ | ||
printf("Enter element at (%d, %d): ", i, j); | ||
scanf("%d", &matrix_one[i][j]); | ||
} | ||
} | ||
|
||
printf("Enter matrix two elements: \n"); | ||
for (i = 0; i < n; i++) | ||
{ | ||
for (j = 0; j < m; j++) | ||
{ | ||
printf("Enter element at (%d, %d): ", i, j); | ||
scanf("%d", &matrix_two[i][j]); | ||
} | ||
} | ||
|
||
multiply_matrices((int *)matrix_one, (int *)matrix_two, m, n); | ||
} |
Oops, something went wrong.