URI Online Judge Solution 1173 Array fill I Using C, Python Programming Language.
Read a number and make a program which puts this number in the first position of an array N[10]. In each subsequent position, put the double of the previous position. For example, if the input number is 1, the array numbers must be 1,2,4,8, and so on.
Input
The input contains an integer number V (V < 50).
Output
Input
The input contains an integer number V (V < 50).
Output
Print the stored number of each array position, in the form "N[i] = X", where i is the position of the array and x is the stored number at the position i. The first number for X is V.
Solution Using C:
#include <stdio.h>
int main() {
int n[10],x,i;
scanf("%d",&x);
for(i=0; i<10; i++)
{
if(i==0)
n[i] = x;
else
n[i] = n[i-1]*2;
}
for(i=0; i<10; i++)
printf("N[%d] = %d\n",i,n[i]);
return 0;
}
int main() {
int n[10],x,i;
scanf("%d",&x);
for(i=0; i<10; i++)
{
if(i==0)
n[i] = x;
else
n[i] = n[i-1]*2;
}
for(i=0; i<10; i++)
printf("N[%d] = %d\n",i,n[i]);
return 0;
}
Comments
Post a Comment