1172 Array Replacement I

SemiColon
By -
0
URI Online Judge | 1172

Array Replacement I

Read an array X[10]. After, replace every null or negative number of X ​by 1. Print all numbers stored in the array X.

Input

The input contains 10 integer numbers. These numbers ​​can be positive or negative.

Output

For each position of the array, print "X [i] = x", where i is the position of the array and x is the number stored in that position.
Input SampleOutput Sample
0
-5
63
0
...
X[0] = 1
X[1] = 1
X[2] = 63
X[3] = 1
...




Solution:
#include <stdio.h>
int main()
{
    int ar[10],i;
    for(i=0; i<10; i++)
        scanf("%d",&ar[i]);
    for(i=0; i<10; i++)
    {
        if(ar[i]<=0)
            ar[i]=1;
    }
    for(i=0; i<10; i++)
        printf("X[%d] = %d\n",i,ar[i]);
    return 0;
}



Tags:

Post a Comment

0Comments

Post a Comment (0)