当前位置:网站首页>输入若干数据,找出最大值输出。(键盘和文件读取)
输入若干数据,找出最大值输出。(键盘和文件读取)
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;
}边栏推荐
猜你喜欢
随机推荐
MySQL连接
C语言入门篇 概述
C语言入门篇 二.函数
【Pytorch】Dataset_DataLoader
C语言从入门到入土——函数
ros启动非本机节点
Data annotation learning summary
C语言起步
Embedded system transplantation [3] - uboot burning and use
使用swagger2markup生成API文档
关于numpy基础用法的一个整理
How to avoid the most common mistakes when building a knowledge base?
Integration of SSM
PPPoE gateway simulation environment setup
用双向链表实现栈(C)
C语言入门篇 五.初识指针 六.初识结构体
yocs_velocity_smoother源码编译
1、基于增量式生成遮挡与对抗抑制的行人再识别
一步一步带你学C(其二)
csgo部分常用服务器指令与一些绑定指令整理









