Babbage problem: Difference between revisions

Content added Content deleted
No edit summary
Line 162: Line 162:
{{out}}
{{out}}
Identical to the first BBC BASIC version.
Identical to the first BBC BASIC version.

=={{header|C}}==
<lang C>
// This code is the implementation of Babbage Problem

#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
int main() {
int current = 0, //the current number
square = 0; //the square of the current number

//the strategy of take the rest of division by 1e06 is
//to take the a number how 6 last digits are 269696
do {
square = current * current;
current++;
} while ((square % 1000000 != 269696)&&(square<INT_MAX));

if (square>+INT_MAX)
printf("Square do not found in the C type limits\n");
else
printf("The square of %d is %d\n", current, square);
return 0 ;
}
</lang>

{{out}}
<pre>The square of 25265 is 638269696</pre>


=={{header|C++}}==
=={{header|C++}}==