Write a program that will read N values of type double from the keyboard and
store the reciprocal of each value (the reciprocal of a value x is 1.0/x) in an array. Display the array.


Difficulty level
This exercise is mostly suitable for students
#include <stdio.h>
#define M 100
void main(void)
{
	int N, i;
	double data[M], v;

	do{
		printf("Enter the dimension: ");
		scanf("%d",&N);
	}while(N<=0 || N>M);

	printf("Enter %d values separated by spaces:\n", N);
	for(i = 0 ; i<N ; i++)
	{
		scanf("%lf", &v);
		data[i]=1/v;
	}

	printf("\nReciprocal of the entered values:\n");
	for(i = 0 ; i<N ; i++)
	{
		printf("%.2lf ",data[i]);
	}
}


Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Implementation of a deque using a circular list