当前位置:网站首页>6-6 批量求和(*)
6-6 批量求和(*)
2022-06-11 17:17:00 【西红柿_码农】
请编写函数,从一个文件中读取实数求和,并将结果写入另一个文件。
函数原型
void BatchAdd(FILE *in, FILE *out);说明:参数 in 和 out 为指示两个文件的指针。函数从 in 所指文件中的读出数据,将结果写入 out 所指的文件中。
要求:in 所指文件中有很多行,每行包含两个实数,以空格间隔。函数求出这两个实数的和,写入 out 文件中,每行一个结果。
要求:输出结果保留 2 位小数。
裁判程序
#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("文件无法打开!");
}
if (in)
{
fclose(in);
}
if (out)
{
fclose(out);
puts("文件保存成功!");
}
return 0;
}
/* 你提交的代码将被嵌在这里 */在程序所在文件夹中创建文本文件“Addition.txt”,复制下面的内容:
Addition.txt
25.9 8.7
120.9 87.518
12.8 65.2
输入样例
(无)
输出样例
文件保存成功!
程序运行结束后,打开“Sum.txt”文件,查看文件内容。
34.60
208.42
78.00void BatchAdd(FILE *in, FILE *out)
{
int i;
double a,b;
while(fscanf(in,"%lf %lf",&a,&b)!=EOF)//读取一次打印一次,注意精确度
{
fprintf(out,"%.2lf\n",a+b);
}
}
边栏推荐
- Authing biweekly news: authing forum launched (4.25-5.8)
- Hands on deep learning - multiple input and output channels in the convolution layer
- Activity | authing's first channel cooperation activity came to a successful conclusion
- Cocoapod only updates the specified library (does not update the index)
- ASP. Net education OA system source code education industry OA system source code with document
- ffmpeg CBR精准码流控制三个步骤
- ffmpeg硬编解码 Inter QSV
- Chip mass production, oppo entering a new era?
- 如何成为一个乐观派组织?
- 啟牛商學院給的證券賬戶是安全的嗎?開戶收費嗎
猜你喜欢

A journey of database full SQL analysis and audit system performance optimization

How to become an optimist organization?

C language: use H and C. summary of problems encountered in documents

Authing CEO 谢扬入选福布斯 2021 年 30 Under 30 亚洲榜单

GUI guess number game, directly open play

ffmpeg硬件编解码Nvidia GPU

Tornado environment construction and basic framework construction -- familiar Hello World

Biden ordered to enforce the zero trust structure

定制 or 订阅?未来中国 SaaS 行业发展趋势是什么?

05_ Feature Engineering - dimension reduction
随机推荐
Classic reading of multi task learning: MMOE model
7 life tools: SWOT, PDCA, 6w2h, smart, WBS, time management, and the 28 principles
Set object mapping + scene 6-face mapping + create space in threejs
Semaphore PV operation of process interaction and its code implementation
LeetCode——24. Exchange the nodes in the linked list in pairs (three pointers)
ffmpeg硬编解码 Inter QSV
Biden ordered to enforce the zero trust structure
ffmpeg奇偶场帧Interlace progressive命令和代码处理
What products are good for cross-border e-commerce? What are the top selling categories?
Is it safe for Xiaobai to open an account directly on the flush?
Oracle analysis function over and MySQL achieve similar effects
Custom or subscription? What is the future development trend of China's SaaS industry?
TypeScipt基础
A journey of database full SQL analysis and audit system performance optimization
Authing 背后的计算哲学
DFS和BFS笔记(一)基于C语言的广度优先搜索
Leetcode 450. Deleting a node in a binary search tree
Oracle generates non duplicate string sys_ Guid() and MySQL generate unique values
信息安全数学基础 Chapter 3——有限域(一)
Hands on deep learning - multiple input and output channels in the convolution layer