#include<stdio.h>int main(){ int n; scanf("%d",&n); int a[n]; for(int i=0;i<n;i++) { scanf("%d",&a[i]); } int max_right=a[n-1]; for(int i=n-2;i>=0;i--) { if(a[i]>max_right) { max_right=a[i]; printf("%d\n",max_right); } }}
Question
#include<stdio.h>int main(){ int n; scanf("%d",&n); int a[n]; for(int i=0;i<n;i++) { scanf("%d",&a[i]); } int max_right=a[n-1]; for(int i=n-2;i>=0;i--) { if(a[i]>max_right) { max_right=a[i]; printf("%d\n",max_right); } }}
Solution
This is a C program that reads an integer 'n' from the user, then reads 'n' more integers and stores them in an array. It then iterates over the array from right to left, keeping track of the maximum value it has seen so far. If it encounters a number that is greater than the current maximum, it updates the maximum and prints it.
Here is a step-by-step explanation:
int n;- Declare an integer variable '
Similar Questions
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.