Skip to content
Snippets Groups Projects
Commit 57bb0fae authored by Lucas Christesen Ahler's avatar Lucas Christesen Ahler
Browse files

input/output exercise

parent 5786dc86
No related branches found
No related tags found
No related merge requests found
LDLIBS = -lm
CFLAGS = -O -Wall -std=gnu11
default: cmdline stdin file
.PHONEY: clean
clean:
$(RM) cmdline stdin file out.txt
#include<stdio.h>
#include<math.h>
#include <stdlib.h>
int main(int argc, char** argv) {
for(int i=1;i<argc;i++) {
double x = atof(argv[i]);
printf("x=%g, sin(x)=%g, cos(x)=%g\n",x,sin(x),cos(x)) ;
}
return 0;
}
\ No newline at end of file
#include<stdio.h>
#include<math.h>
#include <stdlib.h>
int main(int argc, char** argv) {
FILE* in_stream=fopen(argv[1],"r");
FILE* out_stream=fopen(argv[2],"w");
int i=0;
while(1){
double x;
i=fscanf(in_stream,"%lg",&x);
if(i!=EOF) {
fprintf(out_stream,"%s%g%10s%g\n","x=",x,"cos(x)=",cos(x));
}
else{break;}
}
fclose(in_stream);
fclose(out_stream);
return 0;
}
\ No newline at end of file
1
2
3
4
5
6
7
8
\ No newline at end of file
#include<stdio.h>
#include<math.h>
int main() {
int i=0;
while(1){
double x;
i=fscanf(stdin,"%lg",&x);
if(i!=EOF) {
fprintf(stdout,"x=%g, sin(x)=%g, cos(x)=%g\n",x,sin(x),cos(x));
}
else {break;}
}
return 0;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment