URI Online Judge Solution 1172 Array Replacement I Using C, Python Programming Language.
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 Sample | Output Sample |
0 | X[0] = 1 |
Solution Using C:
#include <stdio.h>
int main() {
int i,n[10];
for(i=0; i<10; i++)
{
scanf("%d",&n[i]);
if(n[i]<=0)
n[i] = 1;
}
for(i=0; i<10; i++)
printf("X[%d] = %d\n",i,n[i]);
return 0;
}
int main() {
int i,n[10];
for(i=0; i<10; i++)
{
scanf("%d",&n[i]);
if(n[i]<=0)
n[i] = 1;
}
for(i=0; i<10; i++)
printf("X[%d] = %d\n",i,n[i]);
return 0;
}
Comments
Post a Comment