Write a program that uses while loop that prompts the user to input two integers x, and y. Then output all odd numbers between x and y.
1
Expert's answer
2012-04-26T07:37:25-0400
#include <iostream> using namespace std;
int main() { char answer = 'y'; int x; int y; while (answer != 'n') { cout << "x = "; cin >> x; cout << "y = "; cin >> y; if (x > y) { int c = x; x = y; y = c; } cout << "Odd number between x and y: "; for (int i = x + 1; i < y; i++) if (i % 2 != 0) cout << i << " "; cout << endl; cout << "Once more?(y/n) "; cin >> answer; } return 0; }
Comments
Leave a comment