Minimum Plus Product

Given an integer array as input perform the following operations on the array, in the below specified sequence:

  1. Find the minimum number in the array
  2. Add the minimum number to each element of the array
  3. Multiply the minimum number to each element of the resultant array.
Function Description
Implement the function MinPlusProduct()
Parameters
  • int input1: represents number of elements in array
  • int input2[]: represents an array contains elements
Return
Return the resultant array after performing sequence of steps.
Sample Input1
4
1 5 6 9
Sample output1
2 6 7 10
Sample Input2
5
10 87 63 42 2
Sample output2
24 178 130 88 8
Solution in C JAVA PYTHON
#include<stdio.h>
int* MinPlusProduct(int, int*);
int main() {
  int n,arr[50];
  int* result;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&arr[i]);
  }
  result = MinPlusProduct(n, arr);
  for(int i=0;i<n;i++){
    printf("%d",result[i]);
    if(i<n-1){
      printf(" ");
    }
  }
}

int* MinPlusProduct(int input1,int* input2){
  static int result[50];
  int min=input2[0];
  for(int i=0;i<input1;i++){
    if(min>input2[i]){
      min=input2[i];
    }
  }
  for(int i=0;i<input1;i++){
    result[i]=(input2[i]+min)*min;
  }
  return result;
}