C - Write program to use two arrays

Requirements

Write a program that uses two arrays.

The first array is initialized to the values 10, 12, 14, 15, 16, 18, and 20.

The second array is the same size but not initialized.

In the code, fill the second array with the square root of each of the values from the first array.

Display the results.

Hint

You can use the Math sqrt() function.

Demo

#include <stdio.h>
#include <math.h>

int main()//from w w w.  ja  va 2s .  c om
{
    int first[] = { 10, 12, 14, 15, 16, 18, 20 };
    float second[7];
    int x;

    for(x=0;x<7;x++)
        second[x] = sqrt(first[x]);

    for(x=0;x<7;x++)
        printf("The square root of %d is %.2f\n",first[x],second[x]);
    return(0);
}

Result

Related Exercise