int main void int npts double x npts double m1 printfplea
int main (void) { int npts ; double x [npts] ; double m1; printf(\"please enter a value for number of data points:\ \"); Scanf(\"% I, &npts;); if (npts 0) { printf(\"please enter a valid value less than 10 but greater than 0:\ \"); scanf(\"% i\ \" .&npts;); } else printf (\"please enter values for points :\ \"); scanf (\"% lf\", &x;[npts]); printf(\"mean = %lf\",&mean;); }
Solution
There are basically a few changes that must be done in this code to make it work.
Change 1) x[npts] cannot be declared in line 4 . till line 4 the value of ntps is not known. use x[10] instead. this will improve the program performance.
Change 2) \"npts\" is an integer, thus during scanf in line 7 , scanf(\"%d\",&ntps) must be used.. Note: %f is used for floating point number.
Change 3)After the printf statement in line 15 the following code must be added
m1=0;
for ( i=0; i<ntps;i++)
{
scanf(\"%1f\",&x[i]);
m1=m1+x[i];
}
mean=m1/ntps;
printf(\"mean = %1f\",mean);
do not use &mean , &mean will return the address where it is stored not the value contained in that address.
![int main (void) { int npts ; double x [npts] ; double m1; printf(\ int main (void) { int npts ; double x [npts] ; double m1; printf(\](/WebImages/41/int-main-void-int-npts-double-x-npts-double-m1-printfplea-1125538-1761600064-0.webp)