max till i element

 // Online C++ compiler to run C++ program online

#include <iostream>

#include <climits>

using namespace std;


void display(int *arr, int n){

    for(int i=0;i<n;i++){

        cout<<arr[i];

    }

}



int main() {

    int arr[]={1,0,4,5,4,1,1,7};

    int n=sizeof(arr)/sizeof(int);

    //cout<<n;

    int max=INT_MIN;

    for (int i=0;i<n;i++){

        if(arr[i]<=max){

            arr[i]=max; 

            }

        else {

            max=arr[i];

        }

    }

    display (arr,n);

    


    return 0;

}

Comments

Popular posts from this blog

Sum of Even Numbers till N

Find the Runner-Up Score!

Print All Substrings