Untitled Document

三、找出下面程序（或程序段）中的语法错误，并予以纠正（每小题4分，共8分）
（1）程序功能是倒序输出各给定的字符串。
#include <stdio.h>
void main()
{
char str[5][ ]={"First","Second","Third","Forth","Fifth"};
char *cp[ ]={str[4],str[3],str[2],str[1],str[0]};
int i;

while(i<=5)
{
printf("%c ",*(cp+i));
i++;
}
}
① "char str[5][ ]={"First","Second","Third","Forth","Fifth"};"应为
"char str[5][10 ]={"First","Second","Third","Forth","Fifth"};"
② "while(i<=5)"应为"while(i<5)"
③ "printf("%c ",*(cp+i));"应为"printf("%s",*(cp+i));"
④ "int i;"应为"int i=0;"

（2）程序功能是将各个平方根值放入数组中。
#include <stdio.h>
void main()
{
int max,a,i;
scanf("%d%d",max,a);
double x[max];

for (i=0;i<max;i++)
x[i]=sqrt(a*i);
}
① 增加"#include <math.h>"
② "scanf("%d%d",max,a);"应为"scanf("%d%d",&max,&a);"
③ "double x[max];"改为：
"double *x=new double[max];"
…
"delete []x;"