I'm trying to get the absolute value of each element of an array, but am running into problems. I need to write a function that takes in as its arguments an array of numbers and the number of elements and outputs an array that contaions the absolute value of each number in the input array.
Code:
#include <stdio.h>
#include <math.h>
int abs(int *array, int N);
int main()
{
int array[16] = {0,1,2,3,-4,5,6,7,-8,9,-10,11,12,13,14,20};
int result;
int absolute;
absolute = abs(array,16);
printf("abs is %i", absolute);
return 0;
}
int abs(int *array, int N)
{
int i;
for(i=0; i<N, i++)
if (array[i]<0)
array[i]=array*(-1);
return array;
}