22 lines
632 B
C
22 lines
632 B
C
#include <stdio.h>
|
|
#include <time.h>
|
|
|
|
int main() {
|
|
long timea, timeb, timec;//clock_t timea;
|
|
long a = 1LL, b = 100000000LL;
|
|
long long result1 = 0LL, result2 = 0LL;
|
|
|
|
timea = clock();
|
|
for (long long i = a; i <= b; i++) {
|
|
result1 += i;
|
|
}
|
|
timeb = clock();
|
|
printf("累加结果: %lld, 所用时间: %lf 毫秒\n", result1, (double)(timeb - timea) / CLOCKS_PER_SEC * 1000);
|
|
|
|
result2 = (a + b) * (b - a + 1) / 2;
|
|
timec = clock();
|
|
printf("高斯结果: %lld, 所用时间: %lf 毫秒\n", result2, (double)(timec - timeb) / CLOCKS_PER_SEC * 1000);
|
|
|
|
return 0;
|
|
}
|