Hello, there is a function that rearranges the elements of the array in reverse order. Here is the code:
#include <stdio.h> #include <string.h> #include <stdlib.h> long double array[] = { 0.304411824158121, 0.702270983146229, 0.675987113307883, 0.652289676782947, 0.975411752562938, 0.284802741036713, 0.877898595240810, 0.726726914957288, 0.084725908720116, 0.946546040643011 }; void revarray(void*, unsigned long, unsigned long); int main(int argc, char** argv) { revarray(array, 10, sizeof(long double)); int i; for (i = 0; i < 10; i++) { printf("%.15Lf\n", array[i]); } return 0; } void revarray(void* base, unsigned long nel, unsigned long width) { void* ptr = malloc(width); int i = 0; int k = 0; int len = 0; if (nel % 2 == 0) { len = nel / 2; for (i = 0; i < len; i++) { memccpy(ptr, base + (nel - i - 1)*width, nel, width); memccpy(base + (nel - i - 1)*width, base + i * width, nel, width); memccpy(base + i * width, ptr, nel, width); } } else { len = nel / 2 + 1; for (i = 0; i < len; i++) { if (i == len - 1) { break; } memccpy(ptr, base + i * width, nel, width); memccpy(base + i * width, base + (nel - i - 1)*width, nel, width); memccpy(base + (nel - i - 1)*width, ptr, nel, width); } } free(ptr); } Do not tell me why the function does not work for real numbers, displays all zeros.