Last active
October 24, 2022 17:22
-
-
Save crbyxwpzfl/f4b48f9ab5600133323dd05ad678e2c5 to your computer and use it in GitHub Desktop.
bunch a c scripts jsut tests
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
#include <stdio.h> | |
#include <string.h> | |
void crypto(char *str); | |
int main() { | |
char s1[] = "Ingenieur", s2[] = "", s3[] = "x"; | |
crypto(&s1); printf("*%s*\n", s1); //// Ãœbergabe von s1 | |
crypto(&s2); printf("*%s*\n", s2); //// Ãœbergabe von s2 | |
crypto(&s3); printf("*%s*\n", s3); //// Ãœbergabe von s3 | |
return 0; } | |
void crypto(char *str) { | |
char ch; | |
int i, len = (int)strlen(str); | |
for(i = 0; i < len / 2; ++i) | |
{ | |
ch = str[i]; | |
printf("*%s*\n", str[i]); | |
str[i] = str[len - 1 - i]; | |
str[len - 1 - i] = ch; | |
printf("*%s*\n", str[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
#include <stdio.h> | |
#define N 10 | |
double m1[N][N], m2[N][N], m3[N][N]; | |
void fill1(void); | |
void fill2(void); | |
int main(void) { | |
int x = 6; | |
int z = 10; | |
int c = 10 % 2; | |
printf("*%d*\n", c); | |
fill1(); | |
fill2(); | |
return 0; | |
} | |
void fill1(void) | |
{ | |
int k = 1; | |
for (int i = 0; i < N; i++) | |
{ | |
for (int n = 0; n < N; n++) | |
{ | |
m1[i][n] = k; | |
k++; | |
} | |
} | |
for (int i = 0; i < N; i++) | |
{ | |
for (int n = 0; n < N; n++) | |
{ | |
printf("%5.1f ", m1[i][n]); | |
} | |
printf("\n"); | |
} | |
printf("\n\n"); | |
} | |
void fill2(void) | |
{ | |
int n = -1; | |
int i = -1; | |
do{ | |
i++; | |
do{ | |
n++; | |
if (i == n) | |
{ | |
m2[i][i] = 10.0; | |
} | |
}while (n < N); | |
n = 0; | |
}while (i < N); | |
printf("\n"); | |
for (int i = 0; i < N; i++) | |
{ | |
for (int n = 0; n < N; n++) | |
{ | |
printf("%5.1f ", m2[i][n]); | |
} | |
printf("\n"); | |
} | |
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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
#define DIM 10 | |
double a[DIM][DIM], b[DIM][DIM], c[DIM][DIM]; | |
void mult_a_b(void); | |
void print_c(void); | |
void print_a(void); | |
void print_b(void); | |
void fill_a(void); | |
void fill_b(void); | |
int main(void) | |
{ | |
//mult_a_b(); | |
fill_a(); | |
fill_b(); | |
print_a(); | |
printf("\n"); | |
print_b(); | |
return 0; | |
} | |
void mult_a_b(void) | |
{ | |
int row, col, idx; | |
for(row = 0; row < DIM; ++row) | |
{ | |
for(col = 0; col < DIM; ++col) | |
{ | |
c[row][col] = 0.0; | |
for(idx = 0; idx < DIM; ++idx) | |
c[row][col] += a[row][idx] * b[idx][col]; | |
} | |
} | |
} | |
void print_c(void) | |
{ | |
int row, col; | |
for(row = 0; row < DIM; ++row) | |
{ | |
for(col = 0; col < DIM; ++col) | |
printf("%10.2f", c[row][col]); | |
printf("\n"); | |
} | |
} | |
void print_a(void) | |
{ | |
int row, col; | |
for(row = 0; row < DIM; ++row) | |
{ | |
for(col = 0; col < DIM; ++col) | |
printf("%10.2f", a[row][col]); | |
printf("\n"); | |
} | |
} | |
void print_b(void) | |
{ | |
int row, col; | |
for(row = 0; row < DIM; ++row) | |
{ | |
for(col = 0; col < DIM; ++col) | |
printf("%10.2f", b[row][col]); | |
printf("\n"); | |
} | |
} | |
void fill_a(void) | |
{ | |
int row, col; | |
srand(time(NULL)); | |
for(row = 0; row < DIM; ++row) { | |
for(col = 0; col < DIM; ++col) { | |
a[row][col] = rand() % 2; | |
} | |
} | |
} | |
void fill_b(void) | |
{ | |
int row, col; | |
srand(time(NULL)); | |
for(row = 0; row < DIM; ++row) { | |
for(col = 0; col < DIM; ++col) { | |
if(row == col){b[row][col] = 1;} | |
else {b[row][col] = 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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
void random_double_zw_0_x (void); | |
void random_int_zw_x_y (void); | |
int main(){ | |
random_double_zw_0_x (); | |
random_int_zw_x_y (); | |
return 0; | |
} | |
void random_double_zw_0_x (void) | |
{ | |
srand(time(0)); | |
int x = 1; | |
printf("%f\n", (double)rand()/RAND_MAX-x); | |
} | |
void random_int_zw_x_y (void) | |
{ | |
srand(time(0)); | |
int x = 4; | |
int y = 20; | |
printf("%d\n", rand() % (x - y) + x); | |
} |
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
#include <stdio.h> | |
#include <math.h> | |
#define ANZ 20 | |
double werte[ANZ] = | |
{ 10, 47, 100, 150, 220, 330, 470, 1000, 1500, 2200, 4700, 10000, 22000, 27000, 33000, 47000, 100000, 220000, 470000, 1000000}; | |
int i; | |
int k; | |
int n; | |
int ein; | |
int wiederstand(int ein); | |
int wiederstandkombi(int ein); | |
int main(void) { | |
//array ausgeben | |
//for(i = 0; i < ANZ; i = i + 1) printf("%2d. %7.0f\n", i + 1, werte[i]); | |
scanf("%d", &ein); | |
//eingabe ausgeben | |
//printf("%d\n", ein); | |
//diffenz array ausgeben | |
//for(i = 0; i < ANZ; i = i + 1) printf("%2d. %7.0f\n", i + 1, fabs(ein - werte[i])); | |
wiederstand(ein); | |
wiederstandkombi(ein); | |
return 0; | |
} | |
int wiederstand(ein) { | |
i = 0; | |
while (fabs(ein - werte[i]) > fabs(ein - werte[i + 1])) { | |
i++; | |
} | |
printf("nächster %7.0f diff %7.0f\n", werte[i], fabs(ein - werte[i])); | |
return 0; | |
} | |
int wiederstandkombi(ein) { | |
double kombi[2] = { 1000000, 1000000}; | |
for (n = 0; n < ANZ; n++) { | |
for (k = 0; k < ANZ; k++) { | |
if ( fabs(ein - (werte[n]+werte[k])) < fabs(ein - (kombi[0]+kombi[1])) ) { | |
kombi[0] = werte[n]; | |
kombi[1] = werte[k]; | |
//interations ausgabe | |
//printf("[0] %7.0f [1] %7.0f\n", kombi[0], kombi[1]); | |
} | |
} | |
} | |
printf("kombi %7.0f aus %7.0f , %7.0f\n", kombi[0] + kombi[1], kombi[0], kombi[1]); | |
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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
#include <math.h> | |
double ineration(double b, double a,int z1, int z2); | |
double exakt(double b, double a); | |
int main(void) { | |
printf("sart\n"); | |
int z1 = 0; | |
int z2 = 0; | |
double a, b; | |
double x; | |
double y; | |
scanf ("%lf %lf", &a, &b); | |
int h = ( ( (b + 1) - a) + a); | |
srand(time(NULL)); | |
for (int i = 0; i < 1000; i++) | |
{ | |
x = rand() % h; | |
y = rand() % 2; | |
if ( pow(sin(x), 2) < y ) | |
{ | |
z1++; | |
} | |
else | |
{ | |
z2++; | |
} | |
} | |
double fn = ineration(b, a, z1, z2); | |
double Fx = exakt(b, a); | |
double pro = ( ((Fx/fn) - 1) * 100 ); | |
printf("x %f y %f\n", x, y); | |
printf("a %f b %f\n", a, b); | |
printf("z1% d z2 %d\n\n", z1, z2); | |
printf("fn %0.3f\n", fn); | |
printf("Fx %0.3f\n", Fx); | |
printf("%0.3f %%\n", pro); | |
return 0; | |
} | |
double ineration(double b, double a,int z1, int z2) | |
{ | |
double x = ( ( (b - a) / (z1 + z2) ) * z2); | |
return x; | |
} | |
double exakt(double b, double a) | |
{ | |
double x; | |
if (a < b) | |
{ | |
x = ( ( (b - ( sin(b) * cos(b) ) ) /2 ) - ( (a - ( sin(a) * cos(a)) ) /2 ) ); | |
} | |
else | |
{ | |
x = ( (sin(a) * cos(a))/2 - (sin(b) * cos(b))/2 ); | |
} | |
return x; | |
} |
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
#include <stdio.h> | |
#define anz 50 | |
char ein[anz]; | |
char scan_ein(); | |
void print_ein(void); | |
void print_ein_dec(void); | |
void replace_ein(int *k, int *g); | |
int main(void) | |
{ | |
int klein, gross; | |
scan_ein(); | |
print_ein(); | |
//print_ein_dec(); | |
replace_ein(&klein, &gross); | |
print_ein(); | |
//print_ein_dec(); | |
printf("gross %d\n", gross); | |
printf("klein %d\n", klein); | |
return 0; | |
} | |
char scan_ein() | |
{ | |
fgets(ein, anz, stdin); | |
return 0; | |
} | |
void print_ein(void) | |
{ | |
printf("%s\n", ein); | |
} | |
void print_ein_dec(void) | |
{ | |
for(int i = 0; i < anz; ++i) | |
{ | |
printf("%d ", ein[i]); | |
} | |
printf("\n"); | |
} | |
void replace_ein(int *k, int *g) | |
{ | |
*k = 0; | |
*g = 0; | |
for(int i = 0; i < anz; ++i) | |
{ | |
int var = ein[i]; | |
if(97 <= var && var <= 122) | |
{ | |
ein[i] = var - 32; | |
*k = *k + 1; | |
} | |
else if(65 <= var && var <= 90) | |
{ | |
ein[i] = var + 32; | |
*g = *g + 1; | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment