/* Program for displaying that how many digits of entered number are ODD and how many are EVEN. */ #include <iostream> using namespace std; int main() { int num, countO = 0, countE = 0, rem, odd[10], even[10]; cout << "Enter Number?\t"; cin >> num; while (num != 0) { rem = num % 10; if (rem % 2 == 1) { odd[countO] = rem; countO++; } else { even[countE] = rem; countE++; } num = num / 10; //or n/=10; } cout << "Total ODD digits are " << countO << " which are:\n"; for (int i = countO - 1; i >= 0; i--) cout << odd[i] << "\t"; cout << "\nTotal EVEN digits are " << countE << " which are:\n"; for (int i = countE - 1; i >= 0; i--) cout << even[i] << "\t"; cout << endl; return 0; }
OUTPUT
/* Program for displaying that how many digits of entered number are ODD and how many are EVEN. */ #include <iostream> using namespace std; int main() { int num, countO = 0, countE = 0, rem; cout << "Enter Number?\t"; cin >> num; while (num != 0) { rem = num % 10; if (rem % 2 == 1) { cout << rem << " is an ODD number\n"; countO++; } else { cout << rem << " is an EVEN number\n"; countE++; } num = num / 10; //or n/=10; } cout << "\nTotal ODD digits are " << countO; cout << "\nTotal EVEN digits are " << countE << "\n"; return 0; }
OUTPUT
No comments:
Post a Comment