-
Notifications
You must be signed in to change notification settings - Fork 0
/
area_input.c
73 lines (51 loc) · 1.51 KB
/
area_input.c
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*FILE: area_input.c
Programer: Poruri Sai Rahul rahul.poruri@gmail.com
Date: 29 Jan 2015
Version: Adapted from Original
Revision-History:
Comments:
*/
#include <stdio.h>
#include <math.h>
/************************************************************************************/
int
main(int argc, char *argv[])
{
FILE *input_ptr; /*file that contains the input radius*/
FILE *output_ptr; /*file that contains the area output*/
const double pi = 4. * atan(1.); /*defining pi*/
double r_min, r_max, r; /*radius of the circle*/
double area; /*stores the value of area*/
int N; /*number of data points*/
N = 100;
double inc; /*increment counter*/
int i; /*counter variable*/
char line[256]; /*line buffer to read from input file*/
/*opening file*/
input_ptr = fopen(argv[1], "r");
output_ptr = fopen("output_area.dat","w");
/*this line has the radius*/
fgets(line, sizeof(line), input_ptr);
/*assigning the value of r to the variable r*/
sscanf(line, "%lf", &r_min);
/*this line has the radius*/
fgets(line, sizeof(line), input_ptr);
/*assigning the value of r to the variable r*/
sscanf(line, "%lf", &r_max);
/*calculate area*/
/* area = pi * r * r;
printf("%f, %f \n", r_min, r_max); */
inc = (r_max-r_min)/N;
for(i=0;i<N+1;i++)
{
r = r_min + i*inc;
area = pi * r * r;
fprintf(output_ptr, "%f, %f \n", r, area);
}
/*print output
printf("area of circle is:%f \n", area);*/
/*close file*/
fclose(input_ptr);
fclose(output_ptr);
return(0);
}