Largest product in a series

Project Euler problem #8 solution in C++:

#include <iostream>
#include <string>
using namespace std;
int main(){
  string num=”insert here 1000-digit number from the statement”;
  unsigned long long prod=0,temp;//don’t change the type of variables, there will be really large numbers there
  for(int i=0; i<988; i++){
    temp=1;
    for(int j=i; j<i+13; j++)
    temp*=(num[j]-‘0’);
    if(temp>prod) prod=temp;
  }
  cout << prod << '\n';
  system(“pause”);
  return 0;
}

Leave a Reply

Name *
Email *
Website