Current location - Recipe Complete Network - Complete cookbook of home-style dishes - Write a program in C++. A. prompt the user to enter five decimal places. Print these five decimal places. Convert each decimal to the nearest integer. D. Decimate these five decimal places.
Write a program in C++. A. prompt the user to enter five decimal places. Print these five decimal places. Convert each decimal to the nearest integer. D. Decimate these five decimal places.
# include & ltstdio.h & gt

# include & ltmath.h & gt

# include & ltstring.h & gt

# include & ltstdlib.h & gt

int main()

{

int i,j,k,n,a[6],sum,avg

Floating point f[6], t;

Printf ("Please enter 5 floating-point numbers: \ n");

for(I = 0; I<5; I++)/// Enter 5 decimal places.

{

scanf("%f ",& ampf[I]);

}

sum = 0;

for(I = 0; I<5; i++)

{

t = f[I]-(int)f[I]; ///According to the comparison between the decimal part and 0.5, decide whether to round up or down.

if(t & lt; 0.5)

{

a[I]=(int)f[I];

}

else a[I]=(int)f[I]+ 1;

sum+= a[I]; ///Sum

}

avg = sum/5; ///average

printf("sum = %d,avg = %d\n ",sum,avg);

}