测试1:算10000000000次循环累乘
JAVA版代码:
import java.io.IOException; public class test { public test() { double k = 0; for (int j = 0; j < 100; j++) { for (int i = 0; i < 100000000; i++) { k += 3.1415926 * i * j; } } System.out.println(k); } public static void main(String[] args) throws IOException { new test(); } } C版代码: #include <stdio.h> #include <stdlib.h> #include <time.h> int main() { double k = 0; for(int j=0;j<100;j++) for (int i = 0; i < 100000000; i++) { k += 3.1415926 * i*j; } printf("%f\n",k); system("pause"); }
测试2:
用递归算法算斐波那契第45项
JAVA代码:
public class test { public static int Fibonacci(int n) { if (n < 2) return 1; else { return Fibonacci(n - 1) + Fibonacci(n - 2); } } public static void main(String[] argc) { System.out.println(Fibonacci(45)); } }
C代码:
#include <stdio.h> #include <stdlib.h> int Fibonacci(int n){ if(n<2) return 1; else { return Fibonacci(n-1)+Fibonacci(n-2); } } int main(void) { printf("%d",Fibonacci(45)); system("pause"); return 0; }
