If you're displaying the odd and even numbers using loops, I see no point keeping the first of the three loops. The work it's doing can be done by the other two, lazy loops.
#include <iostream>
usingnamespace std;
int main()
{
int digit[256]; //array will have the capacity to store 256 digits.
int x, n = 100;
digit[0] = 1; //Initializes array with only 1 digit, the digit 1.
int counter = 1; //Initializes digit counter
int carry = 0; //Initializes carry variable to 0
for(int i = 1; i <= n; i += 2) //The product starts with 1 and continues with odd numbers
{ //If it starts with 2 (int i = 2) will continue with even numbers...
for(int j = 0; j < counter; j++)
{
x = digit[j]*i + carry; //x contains the digit by digit product
digit[j] = x % 10; //Contains the digit to store in position j
carry = x / 10; //Contains the carry value that will be stored on later indexes
}
while(carry > 0) //Loop that will store the carry value on array.
{
digit[counter] = carry % 10;
carry /= 10;
counter++; //Increments digit counter
}
}
for(int i = counter - 1; i >= 0; i--)//Printing answer
cout << digit[i];
cout << "\nThe product has " << counter << " digits...\n";
return 0;
}
Output is
1 2
2725392139750729502980713245400918633290796330545803413734328823443106201171875
The product has 79 digits...
@andywestken indeed you are right but as i said i was in a hurry and i pasted the algorithm from vlad from moscow just adding theinterface stuff at the end and i didn't see the final result of the program. I am sorry about that.
@xeimaster i have just shown you how to display the operations in the output but there are still logical problems which were disccused earlier, but if you want combine condor's algorithm ( which seems to be treating the problem well) with my interface and you should get your program. My result was negative beacause the answer had too many digits so the program gave an ilogical answer. I hope you understood me. : )