当前位置:网站首页>输入若干数据,找出最大值输出。(键盘和文件读取)
输入若干数据,找出最大值输出。(键盘和文件读取)
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;
}边栏推荐
猜你喜欢
随机推荐
【Pytorch】conv2d torchvision.transforms
String的字符串常量池和intern()详解
泛型和注解
Token of space renewable energy
MySQL 远程连接错误解决方法
安装Pytorch+anaconda+cuda+cudnn
C语言入门篇 三.数组 四.操作符
Data annotation learning summary
thread
模拟加法 & 结构体基本用法
Web development
【dp】数字三角形
PPPoE gateway simulation environment setup
T 11-20
【常用技巧】
Generics and annotations
AttributeError: ‘NoneType‘ object has no attribute ‘shape‘
【sklearn】PCA
Installation and login login
Machine vision learning summary









