do
{ statements
}
while (condition);
do
{ xold = xnew;
xnew = (xold + a / xold) / 2;
}
while (fabs(xnew - xold) > EPSILON);
Syntax 7.2: do/while Statement do statement while (condition);
|
print table header
double rate;
for (rate = RATE_MIN; rate <= RATE_MAX;
rate = rate + RATE_INCR)
{ print table row
}
int year;
for (year = YEAR_MIN; year <= YEAR_MAX;
year = year + YEAR_INCR)
{ balance = future_value(initial_balance, rate, year);
cout << setw(10) << balance;
}
cout << "Rate ";
int year;
for (year = YEAR_MIN; year <= YEAR_MAX;
year = year + YEAR_INCR)
{ cout << setw(2) << year << " years";
}
[]
[][]
[][][]
[][][][]
for (int i = 1; i <= n; i++)
{ print triangle row
}
for (int j = 1; j <= i; j++) cout << "[]";
cout << "\n";
for (int i = 1; i <= n; i++)
{ for (int j = 1; j <= i; j++) cout << "[]";
cout << "\n";
}
string word;
while (cin >> word)
{ process word
}
on a command line. The input instructions no longer expect input from the keyboard but from the file article.txt.words < article.txt
words < article.txt > output.txt
string line;
while (getline(cin, line))
{ process line
}
char ch;
while (cin.get(ch))
{ process ch
}
int main()
{ int i;
for (i = 1; i <= 10; i++)
{ int r = rand();
cout << r << "\n";
}
return 0;
}
Time now;
int seed = now.seconds_from(Time(0,0,0));
srand(seed);
int rand_int(int a, int b)
{ return a + rand() % (b - a + 1);
}
double rand_double(double a, double b)
{ return a + (b - a) * rand() * (1.0 / RAND_MAX);
}