fork(2) download
  1. #include<stdio.h>
  2.  
  3. void array_multiplication(int A[], int OUTPUT[], int n)
  4. {
  5. // Initializing left and right
  6. int left = 1;
  7. int right = 1;
  8.  
  9. // Initialize the output array
  10. int i = 0;
  11. for (i = 0; i < n; i++)
  12. OUTPUT[i] = 1;
  13.  
  14. for (i = 0; i < n; i++)
  15. {
  16. // Code obtained from http://w...content-available-to-author-only...s.com
  17. // Feel free to copy but please acknowledge if possible
  18. OUTPUT[i] *= left;
  19. OUTPUT[n - 1 - i] *= right;
  20.  
  21. // The variable left stores the multiplication of
  22. // all elements on the left
  23. left *= A[i];
  24.  
  25. // The variable right stores the multiplication of
  26. // all elements on the right
  27. right *= A[n - 1 - i];
  28. }
  29. }
  30.  
  31. int main(void)
  32. {
  33.  
  34. int arr[] = {4, 3, 2, 1, 2};
  35.  
  36. int OUTPUT[5] = {0};
  37.  
  38. array_multiplication(arr, OUTPUT, 5);
  39.  
  40. int i = 0;
  41. for(i=0; i<5; i++)
  42. printf("%d ",OUTPUT[i]);
  43.  
  44. return 0;
  45. }
Success #stdin #stdout 0s 2008KB
stdin
Standard input is empty
stdout
12 16 24 48 24