Question: Write a program that reads in a two-dimensional array representing the coordinates of points in space.
The program should determine the largest absolute value in the array and scale each element of the array by dividing it by this largest value.
The new array, which is called the normalized array, should have the largest value.
The program consists of two functions:
• main() – obtains the number of data points, and the x, y, and z coordinates of each point.
• normalize() – normalize the array.
[double normalize(int input[2][1], int row, int column);
int main()
{
int row1 = 2;
int column1 = 1;
int c[2][1];
double answer, scale1, scale2, scale3, scale4, scale5, scale6;
printf("This program is designed to determine the largest absolute value in a\n");
printf("two-dimensional array and scale each element of the array by dividing it\n");
printf("by this largest value.\n\n");
printf("Enter the coordinate of X1:");
scanf("%d",&c[0][0]);
printf("Enter the coordinate of X2:");
scanf("%d",&c[0][1]);
printf("Enter the coordinate of Y1:");
scanf("%d",&c[1][0]);
printf("Enter the coordinate of Y2:");
scanf("%d",&c[1][1]);
printf("Enter the coordinate of Z1:");
scanf("%d",&c[2][0]);
printf("Enter the coordinate of Z2:");
scanf("%d",&c[2][1]);
printf("Scaled:\n");
printf("Coordinate of X1:%.2f\n", scale1);
printf("Coordinate of Y1:%.2f\n", scale2);
printf("Coordinate of Y1:%.2f\n", scale3);
printf("Coordinate of Y2:%.2f\n", scale4);
printf("Coordinate of Z1:%.2f\n", scale5);
printf("Coordinate of Z2:%.2f\n", scale6);
system("pause");
return 0;
}
double normalize(int input[2][1], int row, int column)
{
int k, l;
int highest = input[0][0];
for( k = 0; k < row; k++)
for( l = 0; l < column; l++)
if ( input[k][l] > highest)
highest = input[k][l];
return highest;
}
]
>>>could anyone pls help me to figure out why i couldn't get the desired output???tq,,,
#include<stdio.h>
#include<stdlib.h>
float normalize (float c, int coord1);
int main()
{
int i,j, coord;
float points[40][3];
float answer;
float scale;
printf("This program is designed to determine the largest absolute value in a\n");
printf("two-dimensional array and scale each element of the array by dividing it\n");
printf("by this largest value.\n\n");
printf("How many coordinates do you have? : ");
scanf("%d", &coord);
for(i = 0; i < coord; i++)
{
printf("Enter coordinate %d <x y z> : ", i+1);
for(j = 0; j < 3; j++)
{
scanf("%.2f", points[i][j]);
}
}
answer = normalize(points[40][3], coord);
printf ("The highest absolute value is %.2f", answer);
for( i = 0; i < coord; i++)
{
printf("Scaled:\n");
for( j = 0; j < 3; j++)
{
scale = (points[i][j]) / answer;
printf("Coordinate of %d:%.2f\n", i, scale);
}
}
system("pause");
return 0;
}
float normalize (float c, int coord1)
{
int k,l;
float highest = c[0][0];
for(k = 0; k < coord1; k++)
{
for(l = 0; l < 3; l++)
{
if(c[k][l]) > highest)
highest = c[k][l];
}
}
return highest;
}
>>>errors:
line 49 - invalid types `float[int]' for array subscript
line 55 - `float[int]' for array subscript
- expected primary-expression before '>' token
- expected `;' before ')' token
#include<stdio.h>
#include<stdlib.h>
float normalize (float c[][3], int coord1);
int main()
{
int i,j, coord;
float points[40][3];
float answer;
float scale;
printf("This program is designed to determine the largest absolute value in a\n");
printf("two-dimensional array and scale each element of the array by dividing it\n");
printf("by this largest value.\n\n");
printf("How many coordinates do you have? : ");
scanf("%d", &coord);
for(i = 0; i < coord; i++)
{
printf("Enter coordinate %d <x y z> : ", i+1);
for(j = 0; j < 3; j++)
{
scanf("%.2f", points[i][j]);
}
}
answer = normalize(points[40][3], coord);
printf ("The highest absolute value is %.2f", answer);
for( i = 0; i < coord; i++)
{
printf("Scaled:\n");
for( j = 0; j < 3; j++)
{
scale = (points[i][j]) / answer;
printf("Coordinate of %d:%.2f\n", i, scale);
}
}
system("pause");
return 0;
}
float normalize (float c[][3], int coord1)
{
int k,l;
float highest = c[0][0];
for(k = 0; k < coord1; k++)
{
for(l = 0; l < 3; l++)
{
if(c[k][l] > highest)
highest = c[k][l];
}
}
return highest;
}
errors:
line 28 :cannot convert `float' to `float (*)[3]' for argument `1' to `float
normalize(float (*)[3], int)'