Editorial
Read the input sequence into an array. Count the number of negative numbers. If it equals 0, then output "NO". Otherwise, output the count of negative numbers and the numbers themselves in reverse order.
Implementation of the algorithm
Declare an array to store the sequence.
int m[101];
Read the input sequence into the array.
scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &m[i]);
In the variable cnt
, count the number of negative numbers.
cnt = 0; for (i = 0; i < n; i++) if (m[i] < 0) cnt++;
If there are no negative numbers, then output "NO".
if (cnt == 0) printf("NO\n"); else { // Output the count of negative numbers. printf("%d\n", cnt); // Output the negative numbers in reverse order. for (i = n - 1; i >= 0; i--) if (m[i] < 0) printf("%d ", m[i]); printf("\n"); }