问题一
#include
double sum(double *v, int n);
main()
{
static double a[20] = {1.0,2.1,3.5,4.4,5.1,6.9,7.8,8.5,9.2,10.1,11.8,12.5,13.2,14.4,15.1,16.6,17.0,18.1,19.2,20.4};
double s;
s = sum(&a,20);
printf("the sum is %f",s);
return 0;
}
double sum(double *v, int n) /* n is the size v[] */
{
int i = 0;
double s = 0.0;
while( i < n )
s += *(v++);
return s;
}
这个程序哪里错了 为什么运行时出错
问题2
#include <stdio.h>
int main()
{
double x;
while (scanf("%lf", &x) == 1) {
if (x < 0.0)
goto negative_alert;
printf("%f %f\n", sqrt(x), sqrt(2 * x));
}
negative_alert: printf("Negative value encountered!\n");
return 0;
}
我编译后 为什么什么都不执行?
问题3
/* A test that fails */
#include <stdio.h>
int main(void)
{
int cnt = 0;
double sum = 0.0, x;
for (x = 0.0; x != 9.9; x += 0.1) { /* trouble! */
sum += x;
printf("cnt = %5d\n", ++cnt);
}
printf("sum = %f\n", sum);
return 0;
}
为什么For循环不会在x=9.9停止 而是疯狂的增长