1178 Array Fill III

Niloy Sarker
By -
0
URI Online Judge | 1178

Array Fill III

Read a number X. Put this X at the first position of an array [100]. In each subsequent position (1 up to 99) put half of the number inserted at the previous position, according to the example below. Print all the vector N.

Input

The input contains a double precision number with four decimal places.

Output

For each position of the array N print "N[i] = Y", where i is the array position and Y is the number stored in that position. Each number of N[...] must be printed with 4 digits after the decimal point.
Input SampleOutput Sample
200.0000N[0] = 200.0000
N[1] = 100.0000
N[2] = 50.0000
N[3] = 25.0000
N[4] = 12.5000
...
Solution:

#include <stdio.h>
int main()
{
   double ar[100], n,temp,res;
   int i;
    scanf ("%lf", &n);

    res = n;
    for(i=0; i<100; i++)
    {
        printf("N[%d] = %.4lf\n",i,res);
        temp = res;
        res = temp/2;
    }
    return 0;
}
Tags:

Post a Comment

0Comments

Post a Comment (0)