From ca81d2faf6ad209ff66b32c7fd430e4353481d53 Mon Sep 17 00:00:00 2001 From: ll <3491383031@qq.com> Date: Fri, 24 Nov 2023 06:38:05 +0000 Subject: [PATCH] =?UTF-8?q?add=20=E8=BF=9E=E7=BB=AD=E6=95=B4=E6=95=B0?= =?UTF-8?q?=E5=92=8C.cpp.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ll <3491383031@qq.com> --- ...5\346\225\264\346\225\260\345\222\214.cpp" | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 "\350\277\236\347\273\255\346\225\264\346\225\260\345\222\214.cpp" diff --git "a/\350\277\236\347\273\255\346\225\264\346\225\260\345\222\214.cpp" "b/\350\277\236\347\273\255\346\225\264\346\225\260\345\222\214.cpp" new file mode 100644 index 00000000..86ce8de3 --- /dev/null +++ "b/\350\277\236\347\273\255\346\225\264\346\225\260\345\222\214.cpp" @@ -0,0 +1,30 @@ +#include +#include +#include +long jisuan1(long n) +{ + long i,sum=0; + for(i=1;i<=n;i++) + sum+=i; + return sum; +} +void shijian1(long n) +{ + clock_t t; + long sum; + t=clock(); + sum=jisuan1(n); + t=clock()-t; + printf("逐个累加法:\n"); + printf("结果:1到%ld之和为%ld\n",n,sum); + printf("用时:%lf秒\n",((float)t)/CLOCKS_PER_SEC); +} +int main() +{ + int n; + printf("n(大于1000000):"); + scanf("%d",&n); + if(n<1000000) return 0; + shijian1(n); + shijian2(n); + return 1; \ No newline at end of file -- Gitee