- #1
nenyan
- 67
- 0
/*find abs value of an array*/
int absv(double *a, int n)
{
int i;
for(i=0;i<n;i++)
{if (a<0)
a=-a;
}
}
int main()
{
double a[7];
int i,j;
for(i=0;i<7;i++)
scanf("%lf\n",&a);
absv(a,7);
for(j=0;j<7;j++)
printf("%e\n",a[j]);
printf("%d,%d",i,j);
}
The result is weird. I can inpute 8 numbers but it output 7 numbers.
You can see both i and j is 7.
Why I can inpute a[7], but I can not output it?
int absv(double *a, int n)
{
int i;
for(i=0;i<n;i++)
{if (a<0)
a=-a;
}
}
int main()
{
double a[7];
int i,j;
for(i=0;i<7;i++)
scanf("%lf\n",&a);
absv(a,7);
for(j=0;j<7;j++)
printf("%e\n",a[j]);
printf("%d,%d",i,j);
}
The result is weird. I can inpute 8 numbers but it output 7 numbers.
You can see both i and j is 7.
Why I can inpute a[7], but I can not output it?