Friday, 28 October 2016

C++ Program To Product Array Such That Product Is Equal To The Product Of All The Elements Of An Array

Problem :- 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]. Solve It Without Using Division Operator And In O(n).

Solution :-

#include<iostream>
using namespace std;
int main()
{
  int a[100];
  int n,i,j,left[100],right[100],product[100];
 
  cout<<"Enter The Size Of An Array \n";
  cin>>n;
 
  cout<<"\nEnter The Elelment Of The Array \n";
 
  for(i=0;i<n;i++)
  {
  cin>>a[i];
}
 
left[0]=1;
  right[n-1]=1;
 
  for(i=1;i<n;i++)
  left[i]=a[i-1]*left[i-1];
  for(j=n-2;j>=0;j--)
  right[j]=a[j+1]*right[j+1];
  cout<<"Product Of Array Without Division Operator\n\n";
  for(i=0;i<n;i++)
  {
    product[i]=left[i]*right[i];
    cout<<product[i]<<" ";
      }
    return 0;
}

Output :-

C++ Program To Product Array Such That Product Is Equal To The Product Of All The Elements Of An Array

Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date. If you have any Query or Question you can ask in the group, I will Try To Solve your Query and try to answers of your Questions withing 24 Hours, You can also Email me or comment below Please suggest to your Friends to join and like our page and don't forget to Subscribe. Enter your Email and click to subscribe.

subodh yadav

Ghanendra Yadav

Hello, I Am Ghanendra Yadav Owner of This Blog, I am professional Blogger and Programmer. I Love Programming, Logo Making, And Banner Designing. My Highest Qualification is MCA From NIT Warangal. You Can Find Me On Social Media Through Below Link And If You Have Any Query Related To Programming And Other Subject Comment Below or You Can Mail Me I Will Try To Answer Within 24 Hours Email:- yghanendra@student.nitw.ac.in

Find me on Social Media

Facebook | Twitter | Google+ | RSS Feed

2 comments:

  1. Thanks for this programming tutorial.

    ReplyDelete
    Replies
    1. Thanks Brother You Like This Tutorial Don't Forget To Share

      Delete