当前位置:网站首页>输入若干数据,找出最大值输出。(键盘和文件读取)
输入若干数据,找出最大值输出。(键盘和文件读取)
2022-07-24 05:16:00 【陌小呆^O^】
键盘输入,直到输入非数终止
#include <iostream>
using namespace std;
int main()
{
int i, j;
cout << "输入若干数据:\n";
cin >> i;
int max = i;
while (cin >> j)
{
if (j > max)
max = j;
}
cout << "最大值MAX = " << max << endl;
return 0;
}文件读取
#include<fstream>
#include<iostream>
using namespace std;
int main()
{
ifstream in;
ofstream out;
int i, j, max;
in.open("1.txt");
out.open("2.txt");
if (!in)
cout << "1.txt打开失败!\n";
if (!out)
cout << "2.txt打开失败!\n";
in >> i;
max = i;
while (in >> j)
{
if (j > max)
max = j;
}
out << "最大值MAX = " << max;
return 0;
}边栏推荐
- I'm interested in reading efficient reading - the most cost-effective self investment
- 股票价格走势的行业关联性
- 【常用技巧】
- Detailed explanation of string constant pool and intern() of string
- Jersey2.25.1集成freemarker
- Add, delete, modify and check JDBC
- 【Pytorch】nn.Module
- yocs_velocity_smoother源码编译
- C语言进阶篇 七.程序的编译和预处理
- Bear market bottoming Guide
猜你喜欢

JDBC encapsulates a parent class to reduce code duplication

c2-随机产生函数种子seed、numpy.random.seed()、tf.random.set_seed学习+转载整理

线程

SSM整合

手写orm框架

Ia notes 2

MySQL insight

The fourth job: about the usage of cat, grep, cut, sort, uniq, VIM, TR and other commands

Tips for using the built-in variable props of BeanShell

Read "effective managers - Drucker"
随机推荐
泛型和注解
yocs_velocity_smoother源码编译
Scikit learn -- steps of machine learning application development
酒店IPTV数字电视系统解决方案
PXE efficient batch network installation
反射的介绍
Bear market bottoming Guide
Hotel IPTV digital TV system solution
Tips for using the built-in variable vars in BeanShell
【sklearn】RF 交叉验证 袋外数据 参数学习曲线 网格搜索
Relational database 10 minutes to understand MySQL
CentOS 7安装Mysql5.6.37
修改jupyter保存路径
NFS shared services
Source code compilation!!
T 6-10
Pointer learning diary (III)
使用swagger2markup生成API文档
【sklearn】tree.DecisionTreeClassifier
一步一步带你学C(其二)