Accuracy problem!
/*
==================================================================
Topic:
Find the last three digits of any number of integers! The last three digits of the 72-time 347 are 241.
==================================================================
*/
#include <stdio.h>
#include <iomanip>
Main ()
{
int x,y,p,n;
printf ("Description: Base x, power Y, please enter: \ n");
printf ("x=");
scanf ("%d", &x);
printf ("y=");
scanf ("%d", &y);
P=1;
for (n=1;n<=y;n++)
{
p=p*x%1000; The key is to grasp the meaning of this sentence, the last three bits are always only the last three bits of the multiplier related, so only the last three bits, so as not to overflow!
printf ("%3d:p=%3d \ n", n,p);//If the output process is not required, this line of code is not required
}
printf ("%d of%d of the last three bits is:%3d\n", x,y,p);
}
/*
====================================================================
Evaluation:
or the application of random numbers, but this is used to deal with a relatively long number, the computer will use this method
Handle your own precision! is to keep only the precision-related parts at a time.
=====================================================================
*/
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The basic algorithm of C language 29-the last three digits of an integer in any order (accuracy problem)