1. ## Please debug the error!

Hi friends, i have written a C-prog,for implementing the equation in the attached file.. plz see the attachment!

assume tau(0)=0
tau(1)=0.1
T=0.1
X(tau(0))=1 as we know X = e^-t
X(tau(1))= X(0.1)= e^-0.1

n=2,3...20.

Code:
```#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float x[20]={0},tau[20]={0},A,B,C,D,e=2.718;
int n,T=0.1;
tau[0]=0;
tau[1]=0.1;
x[0]=pow(e,0);
x[1]=pow(e,-0.1);
clrscr();
for(n=1;n<=20;n++)
{
x[tau[n]]=pow(e,-tau[n]);
x[tau[n-1]]=pow(e,-tau[n-1]);
A=x[tau[n]]-x[tau[n-1]];
B=tau[n]-tau[n-1];
C=A/B;
if(C<0)
C=-C;
D=C+1;
tau[n+1]=tau[n]+T/D;
printf("tau[n+1]=%f\n",tau[n+1]);
}
getch();
}```
This prog is giving some error,if anyone debugs it plz let me know

2. Code:
```for(n=1;n<=20;n++)
{
x[tau[n]]=pow(e,-tau[n]);
x[tau[n-1]]=pow(e,-tau[n-1]);
A=x[tau[n]]-x[tau[n-1]];
B=tau[n]-tau[n-1];
C=A/B;
if(C<0)
C=-C;
D=C+1;
tau[n+1]=tau[n]+T/D;
printf("tau[n+1]=%f\n",tau[n+1]);
}```
in the last two iterations you are trying to access tau[20] and tau[21]....
i think it should be n<19

3. You may want to indent your code to make it more readable.

--
Mats

4. Originally Posted by stewie griffin
Code:
```for(n=1;n<=20;n++)
{
x[tau[n]]=pow(e,-tau[n]);
x[tau[n-1]]=pow(e,-tau[n-1]);
A=x[tau[n]]-x[tau[n-1]];
B=tau[n]-tau[n-1];
C=A/B;
if(C<0)
C=-C;
D=C+1;
tau[n+1]=tau[n]+T/D;
printf("tau[n+1]=%f\n",tau[n+1]);
}```
in the last two iterations you are trying to access tau[20] and tau[21]....
i think it should be n<19
stewie is correct. The maximum element for tau is 19, so 20 and 21 are out-of-bounds.