-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2.c
More file actions
46 lines (33 loc) · 1.13 KB
/
2.c
File metadata and controls
46 lines (33 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <stdio.h>
#include<math.h>
int calculate_order(double wavelength, double theta, double d) {
double wavelength_m = wavelength * 1e-9;
double d_m = d * 1e-6;
double sin_theta = sin(theta * M_PI / 180);
int order = round(d_m * sin_theta / wavelength_m);
return order;
}
int main() {
double wavelength, theta, d;
printf("Enter wavelength (nm): ");
scanf("%lf", &wavelength);
if (wavelength < 380 || wavelength > 750) {
printf("Out of range. Please enter a valid number (380-750 nm).\n");
return 1;
}
printf("Enter angle theta (degrees): ");
scanf("%lf", &theta);
if (theta < 0 || theta > 90) {
printf("Invalid angle. Theta must be between 0 and 90 degrees.\n");
return 1;
}
printf("Enter slit separation d (μm): ");
scanf("%lf", &d);
if (d <= 0) {
printf("Slit separation must be positive.\n");
return 1;
}
int Result = calculate_order(wavelength, theta, d);
printf("%d-th order maxima\n", Result);
return 0;
}