Number
Numberunknown
c_cpp
4 years ago
774 B
6
Indexable
//
// main.cpp
// Sanket
//
// Created by Sid on 28/11/21.
// Copyright © 2021 SidHeart. All rights reserved.
//
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
string n = "73167176531330624919225119674426574742";
int max = 0;
string number = "";
int ndigits = 5;
int first = 0;
while(first < (n.length() - (ndigits - 1))) {
int last = first + ndigits;
string num = n.substr(first, last - first);
cout<<"Next"<<num<<endl;
int total = 1;
for (char i: num) {
total *= (i - '0');
}
if (total > max) {
max = total;
number = num;
}
first += 1;
}
cout<<"Biggest:"<<number<<"Product:"<<max<<endl;
}
Editor is loading...