2 u011622079 u011622079 于 2013.08.08 10:16 提问

想学着用atof 但是不会 求指点

#include
#include
#include

int main(void)
{
float convert, Sum = 0, Average;
char *pTemp = NULL;
int NumTemper, error, i;

do
{
printf("The number of temperatures would you like to enter\n");
fflush(stdin);
error = scanf("%d",&NumTemper);
}while((!error)||(NumTemper<0));

pTemp = (char *) malloc(NumTemper*sizeof(char));

if(pTemp!=NULL)
{
for(i=0; i<NumTemper; i++)
{
printf("\nPlease enter temperature: ");
fflush(stdin);
scanf("%s", &pTemp[i]);

convert[i]=atof(pTemp[i]);
Sum+=convert[i];

}
printf("\n\nThe average is %.2f", Sum/(float)NumTemper);
free(pTemp);
pTemp = NULL;
}
getch();

return 0;
}

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!