Anal is hot!arithma wroteIf I had to choose a trainee who knew how to program and think in comparison to one who knew standards and was anal about it I'd be happy to pick the one who knew how to think.
C Programming Final Exams
1. oh I see... I thought '%d' is for integer...Padre wrote1- Integer
2- There are numerous ways to pass arrays to a function, this is one of them :D
3-Nop, only diagonal. a single loop from 1 till size, and im always taking item 1,1 - 2,2 - 3,3 -> diagonal.
2. Mind mentioning some of the others? :D
3. Oh yeah you're right... But you're missing the other diagonal though... and that can be considered using A[ARY_SIZE - i][ARY_SIZE - i]
Anyway, thanks for the help man. Appreciated :)
That's some crazy code you got there!nuclearcat wrote1.Code is not portable. There is few other tricky ways possible...int func (int *array,int length) { int i; for (i=0;i<(length/2);i++) { array[i] ^= array[length-1-i]; array[length-1-i] ^= array[i]; array[i] ^= array[length-1-i]; } }
Why not just create a new array and fill it backwards?
I know, your code is probably faster, but what difference does it make in this case?
In any case?? Unless you're programming critical kernel functions, in most cases it wont matter.
- Edited
Maybe skirt anal. Even then..rolf wroteAnal is hot!arithma wroteIf I had to choose a trainee who knew how to program and think in comparison to one who knew standards and was anal about it I'd be happy to pick the one who knew how to think.
Kassem, you still need anything?
I just need to understand how to pass an array as an argument of a function. My prof. said the function should be expecting a pointer, but Padre's code doesn't show that...arithma wroteKassem, you still need anything?
void print_ary(int* A, int rows, int columns)
{
int i;
int j;
for (i=0;i<rows;i++)
{
for (j=0;j<columns;j++)
printf("%i \t",A[i*rows+j]);
printf("\n");
}
}
This code will allow you to access 2D arrays of arbitrary width and height. The thing to note is that internally, A[1][0] comes right after A[0][columns-1], that's why we can use index multiplication.You'd pass in print_ary(&A[0][0], ARY_SIZE, ARY_SIZE)..
Enjoy :)
or if you want to keep the A[X][Y] u can use
print_ary(int **A, int rows, int columns)
if i remember correctly- Edited
@nuclearcat, you have a problem in your code,
I think the 3rd line:
It's f*** crazy though, bitwise XOR can actually reverse the array :)
I did it with a paper and a pen, and it works! Took me 1/2 hour to understand.
I think the 3rd line:
array[i] ^= array[length-1-i];
Is a mistake, and it's the same then the 1st one.It's f*** crazy though, bitwise XOR can actually reverse the array :)
I did it with a paper and a pen, and it works! Took me 1/2 hour to understand.
You can't since it has no way to know what size the dimension is (int ** can mean any dimension). What you probably meant was:Padre wroteor if you want to keep the A[X][Y] u can useif i remember correctlyprint_ary(int **A, int rows, int columns)
int (*A)[ARY_SIZE] is the closest thing you'll get.
You can use the A[j] with this declaration, and to pass arguments in as well.
You guys should take the program apart, and implement swap apart from the array reversal to make things clear.
From wikirolf wrote@nuclearcat, you have a problem in your code,
I think the 3rd line:Is a mistake, and it's the same then the 1st one.array[i] ^= array[length-1-i];
It's f*** crazy though, bitwise XOR can actually reverse the array :)
I did it with a paper and a pen, and it works! Took me 1/2 hour to understand.
length-1-i is also correct, so when i have index value 0, i will use to swap it with last element (since count is from 0, then it is length-i-1Conventional swapping requires the use of a temporary storage variable. Using the XOR swap algorithm, however, no temporary storage is needed. The algorithm is as follows:
X := X XOR Y
Y := X XOR Y
X := X XOR Y