Algorithm Analysis
Read the input sequence of numbers into an array. Next, using a loop, we will output all the elements of the array that are greater than their predecessors.
Algorithm Implementation
Declare the working array.
int m[101];
Read the number of input numbers .
scanf("%d", &n);
Read the input array.
for (i = 0; i < n; i++) scanf("%d", &m[i]);
Output the elements of the array that are greater than their predecessors.
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
n = int(input()) lst = list(map(int, input().split())) for i in range(1,n): if lst[i] > lst[i-1]: print(lst[i], end = " ")