Product array puzzle

QUESTION

Given an array arr[ ] of n integers, construct a Product Array prod[ ] (of same size) such that prod[i] is equal to the product of all the elements of arr[ ] except arr[i].\n\nInput:\n\nThe first line of input contains an integer T denoting the number of test cases.\nThe first line of each test case is N,N is the size of array.\nThe second line of each test case contains N input A[i].\n\nOutput:\n\nPrint the Product array prod[ ].\n\nConstraints:\n\n1<=T<=10\n1<=N<=15\n1<=C[i]<=20.

“TESTCASE_1”: “2\n5\n10 3 5 6 2\n2\n12 20\n###—###SEPERATOR—###—\n180 600 360 300 900 \n20 12 “, “TESTCASE_2”: “2\n5\n1 4 7 9 8\n2\n1 2\n###—###SEPERATOR—###—\n2016 504 288 224 252 \n2 1 “, “TESTCASE_3”: “0\n###—###SEPERATOR—###—\n0”, “TESTCASE_4”: “0\n###—###SEPERATOR—###—\n0”, “TESTCASE_5”: “0\n###—###SEPERATOR—###—\n0

ANSWER

#include <iostream>
using namespace std;
int main()
{int t;
 cin>>t;while(t--){
    int n,i,prod=1;
  cin>>n;
  int a[n];
  for(i=0;i<n;i++){
    cin>>a[i];
    prod*=a[i];
  }
  for(i=0;i<n;i++){
    cout<<prod/a[i]<<" ";}cout<<endl;}
	return 0;
}
Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.