Thursday, July 30, 2009

C PROGRAMMERS!! homework help please...?

Write a function that, given a 2D array, will determine the minimum and maximum


values of the array. Use the following two arrays:


40 35 30 25 20


20 30 40 50 60


45 55 65 75 85


30 35 40 45 50











200 300 400 500 600


1000 245 78 123 85


981 1001 575 99 333








(a) Use pointer notation for accessing any array elements; don’t use subscript nota-


tion. For example, within your function use *(*(a + i) + j) instead of a[i][j].


(b) Your function should be able to handle 2D arrays with any number of rows and 5


columns. Don’t hard-code array dimensions other than what is required to create


the arrays, i.e., don’t use something like this:


int rows = 4;


int cols = 5;





(c) Print the maximum and minimum values from main()





This Program must work in Microsoft Visual Studio.


Thanks!

C PROGRAMMERS!! homework help please...?
oh hush. he's not going to get a job if he can't do it himself.





void f(int** arr)


{


int max = 0;


int min = 10000000;


int cols = 5;


int rows = sizeof(*(arr + 0))/sizeof(*(*(arr+0) + 0));


for(int r = 0; r %26lt; rows; r++)


for(int c = 0; c %26lt; cols; c++)


{


if(*(*(arr+r) + c) %26gt; max)


max = *(*(arr+0) + c);


if(*(*(arr+r) + c) %26lt; min)


min = *(*(arr+r) + c);


}


printf("Max: %i",max);


printf("Min: %i",min);


}
Reply:You just need to use a double array, Simple homework.
Reply:.section .data


data_array:


.long (your data here)





.section .text


.globl _start





_start:


movl $0, %esi


movl $0, %eax





new_max:


movl %eax, %ebx





loop_start:


movl data_array(,%esi,4), %eax


cmpl $0, %eax


je loop_end


incl %esi


cmpl %eax, %ebx


jg new_max


jmp loop_start





loop_end:


movl $1, %eax


int $0x80





#lol


No comments:

Post a Comment