The do-While statement in C++
The do-while loop displays the current value of digit, increases its value by 1, and then testes to see if the current value of digit exceeds 9.If so the loop terminates, otherwise the loop continues, using the new value of digit. Note that the test is carried out at the end of each pass through the loop, The net effect is that the loop will be repeated 10 times,resulting in 10 successive line of output.
For example, let us see the calculation for the average of the numbers:
#include<stdio.h>
main ()
{
int n,count = 1;
float x, average, sum =0;
/*initialize and read in a value for n*/
printf ("How many numbers ?");
scanf ("%d" , "%n");
/* read in the numbers 8 */
do
{
//*printf (8 x = 8);
scanf ("%f", &x);
sum +=x;
++count;
} while (count <= n);
/* calculate the average and display the answer*/
average = sum /n
printf ("\ n the average is &f \n", average);
}
0 comments:
Post a Comment