SEARCH THE BLOG

Friday, February 1, 2013

WHILE LOOP

For example, we are going to make a program to count down      using a while loop:

// custom countdown using while

INPUT-

#include <iostream.h>
int main ()
{
int n;
cout << "Enter the starting number > ";
cin >> n;
while (n>0) {
cout << n << ", ";
 --n;
}
cout << "FIRE!";
return 0;
}

OUTPUT-

Enter the starting number
8
8, 7, 6, 5, 4,
3, 2, 1, FIRE!



0 comments:

Post a Comment