Added matrix calcs and time_tests
This commit is contained in:
parent
ba52c3baed
commit
17fadb5151
79
c_projects/matrix_calcs/main.c
Normal file
79
c_projects/matrix_calcs/main.c
Normal file
@ -0,0 +1,79 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
void add(int m, int n, double *A, double *B, double *Y) {
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
int test = 0;
|
||||
for ( i = 0; i < m; i++ ){
|
||||
for ( j = 0; j < n; j++ ){
|
||||
test = i*n + j;
|
||||
Y[in + j] = A[im + j] + B[i*m + j];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
double vector_dot(int n, double a[], double b[]) {
|
||||
volatile int i;
|
||||
double sum = 0;
|
||||
for (i=0; i<n; i++) {
|
||||
sum += a[i]*b[i];
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void transpose(int m, int n, double *A, double *A_t) {
|
||||
for ( int i = 0; i < m; i++ ){
|
||||
for ( int j = 0; j < n; j++ ){
|
||||
A_t[jm + i] = A[in + j];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void linearcomb(int m, int n, double sa, double sb, double *A, double *B, double *Y) {
|
||||
for ( int i = 0; i < m; i++ ){
|
||||
for ( int j = 0; j < n; j++ ){
|
||||
Y[in + j] = (sa * A[in + j]) + (sb * B[i*n + j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void matrix_mult(int m1, int n1m2, int n2, double *A, double *B, double *Y) {
|
||||
for ( int i = 0; i < m1; i++ ){
|
||||
for ( int j = 0; j < n2; j++){
|
||||
for ( int k = 0; k < n1m2; k++ ){
|
||||
Y[in2 + j] += A[in1m2 + k] * B[k * n2 + j];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int is_equal(int m, int n, double *A, double *B) {
|
||||
for ( int i = 0; i < m; i++ ){
|
||||
for ( int j = 0; j < n; j++ ){
|
||||
if ( A[in + j] != B[in + j] ){
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
double* newMatrix(int m, int n) {
|
||||
double *mat;
|
||||
|
||||
mat = (double*)malloc(mnsizeof(double));
|
||||
|
||||
for ( int i = 0; i < m; i++ ){
|
||||
for ( int j = 0; j < n; j++){
|
||||
mat[i*n + j] = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return mat;
|
||||
}
|
13
c_projects/test_char_pointers/another_main.c
Normal file
13
c_projects/test_char_pointers/another_main.c
Normal file
@ -0,0 +1,13 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
char c = 248;
|
||||
printf("Result when numeric character is passed: %c\n", c);
|
||||
|
||||
// c = b;
|
||||
// printf("\nResult when non-numeric character is passed: %d", isdigit(c));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
18
c_projects/test_char_pointers/main.c
Normal file
18
c_projects/test_char_pointers/main.c
Normal file
@ -0,0 +1,18 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(){
|
||||
char *x, *y;
|
||||
char cat_value[100];
|
||||
x = "Hello";
|
||||
y = "World";
|
||||
int cat_size;
|
||||
|
||||
cat_size = sizeof(12 * sizeof(char));
|
||||
|
||||
printf("%s\n", x);
|
||||
snprintf(cat_value, 100, "%s,%s\n", x, y);
|
||||
|
||||
printf("%s", cat_value);
|
||||
|
||||
return 0;
|
||||
}
|
19
c_projects/test_char_pointers/time_pg.c
Normal file
19
c_projects/test_char_pointers/time_pg.c
Normal file
@ -0,0 +1,19 @@
|
||||
/* ctime example */
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
|
||||
int main ()
|
||||
{
|
||||
time_t rawtime;
|
||||
|
||||
time ( &rawtime );
|
||||
|
||||
struct tm *local = localtime(&rawtime);
|
||||
|
||||
printf ( "The current local time is: %04d-%02d-%02d\n", local->tm_wday, local->tm_mon + 1, local->tm_mday );
|
||||
printf ("%d\n", 8*sizeof(int8_t*));
|
||||
printf ("%d\n", 8*sizeof(int8_t));
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user