C Program to derive Table of reciprocals, squares, cubes, and fourth powers

C Program to derive Table of reciprocals, squares, cubes, and fourth powers



#include

int main(void)
{
double data[11][5];
double value = 2.0;
int row = 0;
int col = 0;

for(int row = 0 ; row<11 ; row++)
{
data[row][0] = value;
value += 0.1;
}

for(int row = 0 ; row<11 ; row++)
{
data[row][1] = 1.0/data[row][0]; /* 1/x */
data[row][2] = data[row][0]*data[row][0]; /* x*x */
data[row][3] = data[row][2]*data[row][0]; /* x*x*x */
data[row][4] = data[row][3]*data[row][0]; /* x*x*x*x */
}


printf("\n x ");
printf(" 1/x ");
printf(" x*x ");
printf(" x*x*x ");
printf(" x*x*x*x");

for(int row = 0 ; row<11 ; row++)
{
printf("\n");
for(col = 0 ; col<5 ; col++)
printf("%15.4lf", data[row][col]);
}

printf("\n");
return 0;
}





No comments:

Post a Comment