________________________________________________________________ 1. print a list of all the numbers between A and B inclusive: void print_between(int A, int B) { int x = A; while (x <= B) { cout << x << " "; x = x + 1; } cout << "\n"; } void main() { print_between(1, 20); print_between(17, 43); } ________________________________________________________________ 2. print a centigrade to fahrenheit conversion table for the range 0 to 30 centigrade. void main() { double centi = 0.0; while (centi <= 30.0) { const double fahre = centi*9/5+32; cout << centi << " deg C = " << fahre << " deg F\n"; centi = centi + 2.0; } } ________________________________________________________________ 3. print out the Fibonacci sequence until the value exceeds one million void main() { int A = 0, B = 1; while (B <= 1000000) { cout << B << " "; const int next = A+B; A = B; B = next; } cout << "\n"; } ________________________________________________________________ 4. What is the result of adding together all the numbers between A and B? int add_between(int A, int B) { int N = A, sum = 0; while (N <= B) { sum = sum + N; N = N + 1; } return N; } void main() { cout << "11+12+13+...+24 = " << add_between(11, 24) << "\n"; } ________________________________________________________________ 5. What is the result of adding together the cubes of all the numbers between A and B? int cubes_between(int A, int B) { int N = A, sum = 0; while (N <= B) { sum = sum + N*N*N; N = N+1; } return N; } ________________________________________________________________ 6. Print the number N, padded with spaces so that it occupies exactly 11 characters. int digits_in(int X) { int count = 1; while (X >= 10) { X = X/10; count = count+1; } return count; } void print_so_many_spaces(int num_to_print) { while (num_to_print > 0) { cout << " "; num_to_print = num_to_print-1; } } void print_int_in_eleven_characters(int N) { print_so_many_spaces(11 - digits_in(N)); cout << N; } ________________________________________________________________ 7. What is the Nth number in the Fibonacci sequence? int nth_in_fib(int N) { int A = 0, B = 1, count = 1; while (count < N) { const int next = A+B; A = B; B = next; count = count+1; } return B; } ________________________________________________________________ 8. Show what the multiplication table would look like if we did all our calculations modulo ten. void main() { int row = 0; while (row < 10) { int column = 0; while (column < 10) { cout << " " << row*column%10; column = column+1; } cout << "\n"; row = row+1; } } ________________________________________________________________