### arrays n functions

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,,,
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061`` ``````#include #include 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 : ", 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
Last edited on
Use code tags so we can see what lines the errors correspond to.
Your function states it takes a float, not an array of floats, but on line 49 you are accessing it like it is an array.

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061`` ``````#include #include 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 : ", 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)'
the code can be compiled and run, but then it displays wrong output on normalisation part..

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869`` ``````#include #include float normalize (int c[][3], int coord1); int main() { int i,j, coord; int points[40][3]; float answer; 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("\nEnter coordinate %d : ", i+1); for(j = 0; j < 3; j++) { scanf("%d", &points[i][j]); } } answer = normalize(points, coord); printf("\nThe normalisation of the coordinates is:-\n"); for( i = 0; i < coord; i++) { printf("\nCoordinate %d: ", i+1); for( j = 0; j < 3; j++) { printf("%.2f\t", answer); } printf("\n"); } printf("\n"); system("pause"); return 0; } float normalize (int c[][3], int coord1) { int i,j; float largest = c[0][0]; float scale; for(i = 0; i < coord1; i++) { for(j = 0; j < 3; j++) { if(c[i][j] > largest) largest = c[i][j]; } } for(i = 0; i < coord1; i++) { for(j = 0; j < 3; j++) { scale = (c[i][j]) / largest; } } return scale; }``````

Topic archived. No new replies allowed.