Ok, thanks. One other thing, it seems a lot of you put "//comment" for comments?
Isn't the proper way for comments to be /* comment */?
wouldn't // just screw your progam up?(I really don't use comments very often)
This is a discussion on Hi, could someone help me with arrays? within the C Programming forums, part of the General Programming Boards category; Ok, thanks. One other thing, it seems a lot of you put "//comment" for comments? Isn't the proper way for ...
Ok, thanks. One other thing, it seems a lot of you put "//comment" for comments?
Isn't the proper way for comments to be /* comment */?
wouldn't // just screw your progam up?(I really don't use comments very often)
// is a C++ style comment.
/* */ is a C-style comment (also supported in C++).
*Some* C compilers will allow // in C code, but many will not, so you should never use it if you're programming in C.
Shame on all those people for using // on the C board
Last edited by The V.; 10-17-2001 at 11:59 AM.
Heh, my professor has done the same thing on his web page! Shame on him!
isum
This function will take an integer array of numbers and the array size as its parameters.
It will return the sum of all the numbers in the array as an integer.
dsum
This function will take a double array of numbers and the array size as its parameters.
It will return the sum of all the numbers in the array as a double.
iaverage
This function will take an integer array of numbers and the array size as its parameters.
It will return the average of all the numbers in the array as a double.
daverage
This function will take a double array of numbers and the array size as its parameters.
It will return the average of all the numbers in the array as a double.
imax
This function will take an integer array of numbers and the array size as its parameters.
It will return the largest number in the array.
dmax
This function will take a double array of numbers and the array size as its parameters.
It will return the largest number in the array.
imin
This function will take an integer array of numbers and the array size as its parameters.
It will return the smallest number in the array.
dmin
This function will take a double array of numbers and the array size as its parameters.
It will return the smallest number in the array.
isort
This function will take an integer array of numbers, the array size and a sort value as an integer as its parameters.
This function will sort the array elements in descending order if the sort value is 0.
This function will sort the array elements in ascending order if the sort value is anything else.
This function does NOT return any value.
dsort
This function will take a double array of numbers, the array size and a sort value as an integer as its parameters.
This function will sort the array elements in descending order if the sort value is 0.
This function will sort the array elements in ascending order if the sort value is anything else.
This function does NOT return any value.
isearch
This function should take an integer array as its first parameter, array size as the second parameter, and a search key as the third parameter.
It will return the location number of the search key in the array, if it is found.
If it is not found in the array, it should return -999.
dsearch
This function should take a double array as its first parameter, array size as the second parameter, and a search key as the third parameter.
It will return the location number of the search key in the array, if it is found.
If it is not found in the array, it should return -999.
Code:int isum( int[], int ); int iaverage( int[], int ); int imax( int[], int ); int imin( int[], int ); int isort( int[], int ); int isearch( int[], int, int ); double dsum( double[], int ); double daverage( double[], int ); double dmax ( double[], int ); double dmin ( double[], int ); double dsearch( double[], int, double ); double dsort ( double[], int ); int isum (int iarr[], int num) { int i, sum; for (i=0, sum=0; i < num; i++) sum += iarr[i]; return sum; } int dsum (double darr[], double num,) { double sum; int i; for (i=0, sum=0; i < num; i++) sum += darr[i]; return sum; } int iaverage (int iarr[], int num) { int i, sum, avg; for (i=0, sum=0, avg=0; i < num; i++) sum += iarr[i]; avg = sum/i; return avg; } double daverage (double darr[], int num) { double sum, avg; int i; for (i=0, sum=0, avg=0; i < num; i++) sum += darr[i]; avg = sum/i(double); return avg; } int imax (int iarr[], int num) { int i, max; for (max = -36667, i = 0; i < num; i++) { if (iarr[i] > max) max = iarr[i]; } return max; } double dmax (double darr[], int num) { int i; double max; for (max= -100000, i=0; i < num; i++) { if (darr[i] > max) max = darr[i]; } return max; } int imin (int iarr[], int num) { int i, min; for (min = 36667, i = 0; i < num; i++) { if (iarr[i] < min) min = iarr[i]; } return min; } double dmin (double darr[], int num) { int i; double min; for (min= 1000000, i=0; i < num; i++) { if (darr[i] < min) min = darr[i]; } return min; } int isort(int iarr[], int num) { int temp, pass , i; for ( pass = 0; pass < num - 1; pass++ ) { for ( i = 0; i < num - pass - 1; i++ ) { if ( iarr[ i ] > iarr[ i + 1 ] ) { temp = iarr[ i ]; iarr[ i ] = iarr[ i + 1 ]; iarr[ i + 1 ] = temp; } } } for ( i = 0; i < num; i++ ) return iarr[]; } double dsort(double darr[], int num) { double temp; int pass, i; for ( pass = 0; pass < num - 1; pass++ ) { for ( i = 0; i < num - pass - 1; i++ ) { if ( darr[ i ] > darr[ i + 1 ] ) { temp = darr[ i ]; darr[ i ] = darr[ i + 1 ]; darr[ i + 1 ] = temp; } } } for ( i = 0; i < num; i++ ) return darr[]; } int isearch(int iarr[], int sizeofArray, int key ) { int n; for ( n = 0; n < sizeOfArray; n++ ) { if ( iarr[ n ] == key ) return n; } return -999; } double dsearch( double darr[], int sizeofArray, double key ) { int n; for ( n = 0; n < sizeOfArray; n++ ) { if ( darr[ n ] == key ) return n; } return -999; }
Ok, there are the specifications for my header file, and there IS my header file. Will my functions work? Could someone pretty please make me a test c program to test all the functions?
Here's a good question: Why don't you try it?
Honestly. You wrote them, you know what is expected of them. You must have tested them (right? You _did_ test them?), so it should be a simple task to write a program to try them out.
While I do tend to be helpful, I don't see it my place to compile and try every program every person puts up. So don't take it personal. If you're having problems, I can see where you'd be posting for help. But just to have some one test a function? Why can't you?
Quzah.
Problem solved.