c code to replace with multiplication

  • c
  • write a c code to replace with multiplication in array.

    WAP to replace every dynamic array element by multiplication of previous and next of an n element.

    Code

    #include <stdio.h> #include <stdlib.h> #include <string.h> void display(int *arr, int n) { for (int i = 0; i < n; i++) { printf("%d ", arr[i]); } printf("\n"); } int main() { int n; printf("enter the array size\n"); scanf("%d", &n); int *arr = (int *)malloc(n * sizeof(int)); int *mul = (int *)malloc(n * sizeof(int)); printf("enter the elements\n"); for (int i = 0; i < n; i++) { scanf("%d", &arr[i]); } display(arr,n); mul[0]=arr[0]; mul[n-1]=arr[n-1]; for (int i = 1 ; i < n-1; i++) { mul[i]= arr[i-1]*arr[i+1]; } for (int i = 0; i < n; i++) { arr[i]=mul[i]; } display(arr,n); return 0; }