当前位置:网站首页>6-6 batch sum (*)
6-6 batch sum (*)
2022-06-11 17:37:00 【Tomatoes_ Menon】
Please write a function , Read the sum of real numbers from a file , And write the results to another file .
The function prototype
void BatchAdd(FILE *in, FILE *out);explain : Parameters in and out Is a pointer to two files . Function from in Read out data in the indicated file , Write results to out In the document in question .
requirement :in There are many lines in the file , Each line contains two real numbers , In space . Function to find the sum of these two real numbers , write in out In file , One result per line .
requirement : The output results are retained 2 Decimal place .
judging procedures
#include <stdio.h>
#include <stdlib.h>
void BatchAdd(FILE *in, FILE *out);
int main()
{
FILE *in, *out;
in = fopen("Addition.txt", "r");
out = fopen("Sum.txt", "w");
if (in && out)
{
BatchAdd(in, out);
}
else
{
puts(" The file could not be opened !");
}
if (in)
{
fclose(in);
}
if (out)
{
fclose(out);
puts(" File saved successfully !");
}
return 0;
}
/* The code you submit will be embedded here */Create a text file in the folder where the program is located “Addition.txt”, Copy the following :
Addition.txt
25.9 8.7
120.9 87.518
12.8 65.2
sample input
( nothing )
sample output
File saved successfully !
After program running , open “Sum.txt” file , View file contents .
34.60
208.42
78.00void BatchAdd(FILE *in, FILE *out)
{
int i;
double a,b;
while(fscanf(in,"%lf %lf",&a,&b)!=EOF)// Read once print once , Pay attention to accuracy
{
fprintf(out,"%.2lf\n",a+b);
}
}
边栏推荐
- 合并两个有序链表---2022/02/24
- Merge K ascending linked lists ---2022/02/26
- Test and analysis of tidb write hotspot
- Mathematical basis of information security Chapter 1 - Division
- Tidb CDC create task error unknown or incorrect time zone
- R语言寻找数据集缺失值位置
- Export data prompt -- solution to the problem of secure file priv option
- Splitting method of MySQL large tables
- Authing CEO 谢扬入选福布斯 2021 年 30 Under 30 亚洲榜单
- What is the minimum change price of PTA futures? How can PTA futures be safe?
猜你喜欢

Service learning notes 01 start method and life cycle

Leetcode force deduction question

【线上问题】Timeout waiting for connection from pool 问题排查

Merge two ordered linked lists ---2022/02/24

Read and understand the development plan for software and information technology service industry during the "14th five year plan"

05_ Feature Engineering - dimension reduction

which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_ mod

使用exe4j 将.jar文件打包为.exe文件

Authing Share|理解 SAML2 协议

从制造到“智造”,探索制造企业破局之道
随机推荐
vscode保存代碼時自動eslint格式化
Merge K ascending linked lists ---2022/02/26
测试基础之:黑盒测试
Service learning notes 02- actual combat startservice and bindservice
聚类方法汇总
Mathematical basis of information security Chapter 1 - Division
Authing CEO 谢扬入选福布斯 2021 年 30 Under 30 亚洲榜单
[MySQL] detailed explanation of redo log, undo log and binlog (4)
Export data prompt -- solution to the problem of secure file priv option
6-5 统计单词数量(文件)(*)
Sohu tout le personnel a été escroqué, quels problèmes ont été exposés?
sql server中关于FORCESCAN的使用以及注意项
Service learning notes 04 other service implementation methods and alternative methods
通过Xshell连接有跳板机/堡垒机的服务器
Windows technology - how to view the instruction set, model, attribute and other details supported by the CPU, and how to use the CPU-Z tool to view the processor, memory, graphics card, motherboard,
定制 or 订阅?未来中国 SaaS 行业发展趋势是什么?
require和ES6 import的区别
信息安全数学基础 Chapter 1——整除
Splitting method of MySQL large tables
From manufacturing to "intelligent manufacturing", explore the way for manufacturing enterprises to break the situation