file2.cを改訂して,test.datにはsin(1.0)を,
test2.datにはcos(1.0)を書き込むようにして下さい.
| file2.c |
|---|
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(void){
FILE *fp;
fp=fopen("test.dat", "w");
if(fp==NULL){
printf("File Can't Open\n");
exit(1);
}
fprintf(fp, "%f\n", sin(1.0));
fclose(fp);
return 0;
}
|
| file2_1.c |
|---|
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(void){
FILE *fp1, *fp2;
fp1=fopen("test.dat", "w");
if(fp1==NULL){
printf("File Can't Open\n");
exit(1);
}
fp2=fopen("test2.dat", "w");
if(fp2==NULL){
printf("File Can't Open\n");
exit(1);
}
fprintf(fp1, "%f\n", sin(1.0));
fprintf(fp2, "%f\n", cos(1.0));
fclose(fp1);
fclose(fp2);
return 0;
}
|
| file2_2.c |
|---|
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(void){
FILE *fp;
fp=fopen("test.dat", "w");
if(fp==NULL){
printf("File Can't Open\n");
exit(1);
}
fprintf(fp, "%f\n", sin(1.0));
fclose(fp);
fp=fopen("test2.dat", "w");
if(fp==NULL){
printf("File Can't Open\n");
exit(1);
}
fprintf(fp, "%f\n", cos(1.0));
fclose(fp);
return 0;
}
|
| vector_subtract_file.c |
|---|
#include<stdio.h>
void subtract(double *lhs, double *rhs, int size, double *result);
int main(void){
double a[7], b[7], c[5], d[5];
int i;
double a_sub_b[7], c_sub_d[5];
FILE *fp;
a[0]=0.1; a[1]=0.2; a[2]=0.3; a[3]=0.4; a[4]=0.5; a[5]=0.6; a[6]=0.7;
b[0]=1.1; b[1]=2.2; b[2]=3.3; b[3]=4.4; b[4]=5.5; b[5]=6.6; b[6]=7.7;
c[0]=0.5; c[1]=0.6; c[2]=0.7; c[3]=0.8; c[4]=0.9;
d[0]=11.0; d[1]=22.1; d[2]=33.2; d[3]=44.3; d[4]=55.4;
fp=fopen("vector_subtract.dat", "w");
if(fp==NULL){
printf("File can't open.\n");
exit(1);
}
fprintf(fp, "a:\n");
for(i=0;i<7;i++){
fprintf(fp, "a[%d]=%f\n", i, a[i]);
}
fprintf(fp, "b:\n");
for(i=0;i<7;i++){
fprintf(fp, "b[%d]=%f\n", i, b[i]);
}
subtract(a, b, 7, a_sub_b);
fprintf(fp, "a_sub_b:\n");
for(i=0;i<7;i++){
fprintf(fp, "a_sub_b[%d]=%f\n", i, a_sub_b[i]);
}
fprintf(fp, "c:\n");
for(i=0;i<5;i++){
fprintf(fp, "c[%d]=%f\n", i, c[i]);
}
fprintf(fp, "d:\n");
for(i=0;i<5;i++){
fprintf(fp, "d[%d]=%f\n", i, d[i]);
}
subtract(c, d, 5, c_sub_d);
fprintf(fp, "c_sub_d:\n");
for(i=0;i<5;i++){
fprintf(fp, "c_sub_d[%d]=%f\n", i, c_sub_d[i]);
}
return 0;
}
void subtract(double *lhs, double *rhs, int size, double *result){
int i;
for(i=0;i<size;i++){
result[i]=lhs[i]-rhs[i];
}
return;
}
|
fp1=fopen("test.dat", "w");
if(fp1==NULL){
printf("File Can't Open\n");
exit(1);
}
fp2=fopen("test2.dat", "w");
if(fp2==NULL){
printf("File Can't Open\n");
exit(1);
}
fprintf(fp1, "%f\n", sin(1.0));
fclose(fp1);
fprintf(fp2, "%f\n", cos(1.0));
fclose(fp2);
|
fp1=fopen("test.dat", "w");
if(fp1==NULL){
printf("File Can't Open\n");
exit(1);
}
fprintf(fp1, "%f\n", sin(1.0));
fclose(fp1);
fp2=fopen("test2.dat", "w");
if(fp2==NULL){
printf("File Can't Open\n");
exit(1);
}
fprintf(fp2, "%f\n", cos(1.0));
fclose(fp2);
|
FILE *fp;
fp=fopen("test.dat", "w");
if(fp==NULL)
{
printf("File Can't Open\n");
exit(1);
}
FILE *fp;
fp=fopen("test2.dat", "w");
if(fp==NULL)
{
printf("File Can't Open\n");
exit(1);
}
|
警告: ISO C90 forbids mixed declarations and code |