?? algo1-1.c
字號:
/* algo1-1.c 計算1-1/x+1/x*x… */
#include<stdio.h>
#include<sys/timeb.h>
void main()
{
struct timeb t1,t2;
long t;
double x,sum=1,sum1;
int i,j,n;
printf("請輸入x n:");
scanf("%lf%d",&x,&n);
ftime(&t1); /* 求得當前時間 */
for(i=1;i<=n;i++)
{
sum1=1;
for(j=1;j<=i;j++)
sum1=-sum1/x;
sum+=sum1;
}
ftime(&t2); /* 求得當前時間 */
t=(t2.time-t1.time)*1000+(t2.millitm-t1.millitm); /* 計算時間差 */
printf("sum=%lf 用時%ld毫秒\n",sum,t);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -