#include
#include
#include
Long add1 (n)
{
Long I, a=0;
for(i=1; i<=n; I++)
A=a + I;
Return a;
}
Void AddTime1 (n)
{
Clock_t t;
Long sum=0;
T=clock ();
Sum=add1 (n);
T=clock () - t;
Methods: printf (" \ n ");
Printf (" results: the sum of 1 ~ % d: % ld \ n ", n, sum);
Printf (" available: lf % s \ n ", (t) (float)/CLOCKS_PER_SEC);
}
Long add2 (n)
{
Return n * (n + 1)/2;
}
Void AddTime2 (n)
{
Clock_t t;
Long sum;
T=clock ();
Sum=add2 (n);
T=clock () - t;
Method 2: printf (" \ n ");
Printf (" results: the sum of 1 ~ % d: % ld \ n ", n, sum);
Printf (" available: lf % s \ n ", (t) (float)/CLOCKS_PER_SEC);
}
Int main ()
{
int n;
Printf (" n (greater than 1000000) : ");
The scanf (" % d ", & amp; N);
If (n<1000000) return 0;
AddTime1 (n);
AddTime2 (n);
return 1;
}
Why does it have to be input method is one of the 9999999 and negative
Input method 2 1000001 and is negative
The input 99999999 two methods are to
CodePudding user response:
You see your editor long type and the scope of type int, generally as int and long range, you try with the following statement,Printf (" % d \ n ", __INT_MAX__);
Printf (" % ld \ n ", __LONG_MAX__);
Printf (" % LLD \ n ", __LONG_LONG_MAX__);
Two methods from the perspective of the output of your apparent results than the int the maximum range, long long should instead,
CodePudding user response: