English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Write a function in C that takes 3 parameters: the address of a 2-dimensional array of type int, the number of rows in the array, and the number of columns in the array. Have the function calculate the sum of the squares of the elements. For example, for the array nums that is pictured as:
23 12 14 3
31 25 41 17
the call to the function might be
sumsquares ( nums, 2, 4 ) ;
and the value returned would be 4434. Write a short program to test the function.

2006-11-19 15:09:28 · 3 answers · asked by missbehavin288 1 in Computers & Internet Programming & Design

3 answers

You are seriously going to be the worst programmer ever, if you even pass the class your in. According to your profile, you haven't asked a question yet, where you needed someone to do your assignment for you, and your not even willing to pay us for our time.

2006-11-19 15:40:00 · answer #1 · answered by D 4 · 0 0

the errors messages you're seeing are in all probability pertaining to to a pair confusion approximately function declarations and definitions. This code: void removeALL (int array[],int lenght,int removeitem) int significant() { void RemoveAll (int array[], int length, int removeItem) { won't fly simply by fact the 1st void removeALL( line has no semi-colon terminating it. This makes it look like the beginning up of a function definition (the place the definitely code is) on a similar time as you in all probability elect it to be a function statement, which only tells the C compiler what it is going to look like. because it stands, the int significant() that follows it is going to fully confuse the compiler, which predicted a { after the hollow line of removeALL. The semi-colon will restoration this. 2nd, the line void RemoveAll( int array[], int length, int removeItem) additionally happens interior the definition of the main significant() function. C would not enable function definitions interior different purposes. additionally, you in all probability elect to reconcile the capitalization between removeALL() and RemoveAll(). To C, those are 2 completely diverse purposes. desire that enables.

2016-10-22 09:43:48 · answer #2 · answered by Anonymous · 0 0

In C, when you pass an array as an argument, only the last dimension can be unknown.... but a two-dimensional array can be flattened:

int sumsquares(const int* array, int rows, int cols)
{
int elements = rows * cols;
int sum = 0;
while (elements-- > 0)
sum += array[elements] * array[elements];
return sum;
}

2006-11-19 15:14:01 · answer #3 · answered by Ben 2 · 1 0

fedest.com, questions and answers