Previous Next
0 / 21
Module DEMO-32-106DEMO-C-32

Replace Negatives

DEMO-C-32 โ€ข Programming in C

Browser-only practice

Problem Statement

Write a C program to modify a 1D array by replacing all negative numbers with 0. Positive numbers and zeros should remain unchanged. Print the modified array.

Example

Input:

5 10 -5 20 -8 30

Output:

10 0 20 0 30

Constraints

1 <= n <= 100

Input Format

n followed by n integers

Output Format

Modified array

Sample Testcases

Submit runs every public testcase in this browser. Results and code never leave this device.

Sample #1
Public sample
5
10 -5 20 -8 30
10 0 20 0 30
-5 and -8 replaced by 0.
Sample #2
Public sample
3
1 2 3
1 2 3
No negatives, no change.
Sample #3
Public sample
1
-100
0
Single negative element.

Web terminal

C, C++, Java, and Python run locally in a browser VM. No worker or visualizer is used.

Saved in this browser
Editor settings