Leena Lavanya

September 4, 2018

Daily Coding Problem: Problem #2

The Daily Coding Problem (Day 2) was given an array of integers, to return another array of integers consisting of the product of all the integers of the original array except the one at place i (i being the place of each integer in the original list). For instance, an array of [1, 2, 3] should return [6, 3, 2].

#include <iostream>
#include <vector>
using namespace std;

int main()
{
    vector<int> ints;
    int product = 1;
    int n;
    
    while (cin >> n) {ints.push_back(n); product*=n;}
    
    for (int i = 0; i < ints.size(); ++i) cout << (product / ints[i]) << " ";
}
© Copyright 2021 Leena Lavanya. Icons by Font Awesome. Image Credit: Taras Shypka on Unsplash.