Read the sequence of numbers and store it in an array. Then, using a loop, print all elements that are strictly greater than the previous element.
Algorithm implementation
Declare an array.
int m[101];Read the number of input elements .
scanf("%d",&n);Read the input array.
for (i = 0; i < n; i++)
scanf("%d", &m[i]);Print all elements of the array that are strictly greater than the previous element.
for (i = 1; i < n; i++)
if (m[i] > m[i - 1]) printf("%d ", m[i]);Java implementation
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner con = new Scanner(System.in);
int n = con.nextInt();
int m[] = new int[n];
for(int i = 0; i < n; i++)
m[i] = con.nextInt();
for (int i = 1; i < n; i++)
if (m[i] > m[i-1]) System.out.print(m[i] + " ");
System.out.println();
con.close();
}
}Python implementation
Read the input data.
n = int(input())
lst = list(map(int, input().split()))Print all elements of the array that are strictly greater than the previous element.
for i in range(1,n):
if lst[i] > lst[i-1]: print(lst[i], end = " ")