c14
This commit is contained in:
parent
5af4c707eb
commit
7bb7fc04b1
1
C14/Makefile
Normal file
1
C14/Makefile
Normal file
@ -0,0 +1 @@
|
||||
include ../Makefile
|
32
C14/ex1.c
Normal file
32
C14/ex1.c
Normal file
@ -0,0 +1,32 @@
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
void cartesian_to_polar(float x, float y, float *r, float *theta) {
|
||||
*r = sqrtf(x*x + y*y);
|
||||
*theta = y/x;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int rc;
|
||||
float x, y, r, theta;
|
||||
|
||||
printf("x: ");
|
||||
rc = scanf("%f", &x);
|
||||
// check that scanf was successful by checking if it returned 1 (1 successfully scanned item)
|
||||
if (rc != 1) {
|
||||
printf("Please enter a real number\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("y: ");
|
||||
rc = scanf("%f", &y);
|
||||
if (rc != 1) {
|
||||
printf("Please enter a real number\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
cartesian_to_polar(x, y, &r, &theta);
|
||||
printf("r=%f theta=%f\n", r, theta);
|
||||
|
||||
return 0;
|
||||
}
|
29
C14/ex2.c
Normal file
29
C14/ex2.c
Normal file
@ -0,0 +1,29 @@
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
|
||||
float degrees_to_radians(float degrees) {
|
||||
return M_PI * degrees / 180.0;
|
||||
}
|
||||
|
||||
void process(float degrees, float* radians, float* sin_val, float* cos_val, float* tan_val) {
|
||||
*radians = degrees_to_radians(degrees);
|
||||
*sin_val = sin(*radians);
|
||||
*cos_val = cos(*radians);
|
||||
*tan_val = tan(*radians);
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
float degrees, radians, sin_val, cos_val, tan_val;
|
||||
|
||||
printf("Degrees: ");
|
||||
scanf("%f", °rees);
|
||||
|
||||
process(degrees, &radians, &sin_val, &cos_val, &tan_val);
|
||||
|
||||
printf("Radians: %f\n", radians);
|
||||
printf("Sine: %f\n", sin_val);
|
||||
printf("Cosine: %f\n", cos_val);
|
||||
printf("Tangent: %f\n", tan_val);
|
||||
}
|
33
C14/ex3.c
Normal file
33
C14/ex3.c
Normal file
@ -0,0 +1,33 @@
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
|
||||
float degrees_to_radians(float degrees) {
|
||||
return M_PI * degrees / 180.0;
|
||||
}
|
||||
|
||||
void process(float degrees, float* radians, float* sin_val, float* cos_val, float* tan_val) {
|
||||
*radians = degrees_to_radians(degrees);
|
||||
*sin_val = sin(*radians);
|
||||
*cos_val = cos(*radians);
|
||||
*tan_val = tan(*radians);
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
int degrees_start, degrees_end;
|
||||
float radians, sin_val, cos_val, tan_val;
|
||||
|
||||
printf("Start: ");
|
||||
scanf("%d", °rees_start);
|
||||
printf("End: ");
|
||||
scanf("%d", °rees_end);
|
||||
printf("Degs\tRad\tsin\tcos\ttan\n");
|
||||
|
||||
for (int i = degrees_start; i <= degrees_end; i++) {
|
||||
process((float)i, &radians, &sin_val, &cos_val, &tan_val);
|
||||
printf("%d\t%0.3f\t%0.3f\t%0.3f\t%0.3f\n", i, radians, sin_val, cos_val, tan_val);
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user