Q1. To take n input numbers and find maximum of them without storing them

#include <iostream>
using namespace std;
int main(){
    int n;
    int max;

    for(int i=0;i<n;i++){
        cin>>n;
        if(i == 0){
            max = n;
        }
        else{
            if(n > max){
                max = n;
            }
        }
    }
    cout<<max<<endl;
    return 0;
}

Comments

Popular Posts