问题描述
- 想学着用atof 但是不会 求指点
- #include
#include
#includeint main(void)
{
float convert Sum = 0 Average;
char *pTemp = NULL;
int NumTemper error i;do
{
printf(""The number of temperatures would you like to entern"");
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(""nnThe average is %.2f"" Sum/(float)NumTemper);
free(pTemp);
pTemp = NULL;
}
getch();return 0;
}
时间: 2024-11-08 21:57:45