Product of all but one number in a sequence I was given the following prompt in a coding interview:

Given an array of integers, return a new array such that each element at index i of the new array is the product of all the numbers in the original array except the one at i.
For example, if our input was [1, 2, 3, 4, 5], the expected output would be [120, 60, 40, 30, 24]

I solved this in two ways:

fun multiplies all elements together in the first iteration, and then loops again and divides by the number at that position
fun2 does not use division, and instead iteratively builds up the sum in each index

#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;

int fun(int* nums, int arr_size)
{
    int sum;
    int i;
    
    for(i=0, sum=1; i&lt;arr_size; i++)
        sum*=nums[i];
    for(i=0; i&lt;arr_size; i++)
        nums[i]=sum/nums[i];
    return 0;
}

int fun2(int* nums, int arr_size)
{
    int i,j;
    int sum=1;
    int new_arr[arr_size];
  
    for(i=0; i&lt;arr_size; i++) {
        for(j=0; j&lt;arr_size; j++) {
            if(i!=j)
                sum*=nums[j]; //skip member same index in the loop
        }
        new_arr[i]=sum;
        sum=1; 
    }
    memcpy(nums, new_arr, arr_size*sizeof(int));
    return 0;
}

int main(void)
{
    /*Given an array of integers, return a new array such that each element at index i of the 
    new array is the product of all the numbers in the original array except the one at i.
    For example, if our input was [1, 2, 3, 4, 5], the expected output would be 
    [120, 60, 40, 30, 24] */
    int nums[] = {1, 2, 2, 4, 6};    
    int size = sizeof(nums)/sizeof(nums[0]);
    int i;
    fun(nums, size);
    for (i = 0; i &lt; size; i++) 
        printf(&quot;%d &quot;, nums[i]); 
    
    //what if you can't use division?
    printf(&quot;\n&quot;);
    int nums2[] = {1, 2, 2, 4, 6}; 
    fun2(nums2, size);
    for (i = 0; i &lt; size; i++) 
        printf(&quot;%d &quot;, nums2[i]);
   
    return 0;
}
```
Here are some things that may help you improve your code.
Use all required #includes
The code uses memcpy, so it should #include &lt;string.h&gt;.  It might still compile on your machine, with your compiler, but it's not portable.
Think about potential errors
As one of the comments correctly notes, if one of the entries has the value of zero, this line will have a problem:
nums[i]=sum/nums[i];

Also, what happens if the passed arr_size is zero or negative?  What should the function return if there is exactly one item in the array? What if the passed pointer is NULL?
Follow directions exactly
The problem says to &quot;return a new array&quot; but that is not really what this code is doing.  This code is overwriting the input array.  One of the problems with that is that it's not possible to call this with a const pointer as mentioned in the next suggestion.  It also means that rather than returning a meaningless constant value in all cases, the function should probably return a pointer.
Use const where practical
As mentioned above, the code should return a new array rather than overwriting the passed one.  I would suggest that the function should be something like this:
int* exclusive_product(const int* nums, size_t nums_size)

Note that first, we use const and second, we use size_t rather than int for the second argument to more clearly indicate the type of variable we are expecting.
Use better variable names
I would say that nums, size and i are good variable names, but that fun and fun2 and definitely sum are not.  The problem is that fun doesn't tell the reader anything about what the code is supposed to do and sum is actually misleading (it's a product, not a sum).
Think about an efficient way to solve this
The \$O(n^2)\$ code you have in fun2 is not a terrible way to solve the problem and has the advantage of being obviously correct.  When I interview people, I typically like such answers because it's much easier to make slow correct code fast than it is to make fast incorrect code correct.  However, in a good interview, I like to ask the candidate to make comments on his or her own code, including any limitations, assumptions or potential improvements that might be made.  In this case, it helps if we think mathematically about the final values in the resulting array \$B\$ from input array \$A\$.  For example, we know that every value \$B_j\$ can be expressed as the product $$\displaystyle B_j = \prod_{i=0}^{j-1} A_i \prod_{i=j+1}^{n-1} A_i$$ if \$n\$ is the length of the array.  This suggests a more efficient approach I'll leave for you to figure out.