c或c++利用scanf无限输入并进行简单操作如比大小等

#include <iostream>
using namespace std;
int main() {
    int n,max=0;
    while (scanf("%d",&n)==1)
    //scanf返回值为int类型表示成功输入的数据数量个数
    {
        if(n>max)    max=n;
    }
    printf("%d",max);
    return 0;
}
    

C语言:

#include <stdio.h>
int main() {
    int n,max=0;
    while (scanf("%d",&n)==1)
    //scanf返回值为int类型表示成功输入的数据数量个数
    {
        if(n>max)    max=n;
    }
    printf("%d",max);
    return 0;
}
    

 


    

原文地址:https://www.cnblogs.com/XUEYEYU/p/C-scanf.html