move exercises, lecture examples, labs into subfolders
This commit is contained in:
32
Exercises/C14/ex1.c
Normal file
32
Exercises/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;
|
||||
}
|
||||
Reference in New Issue
Block a user