Counting The Number of Zero In Input (C++)
1. User can input a simple integer. For example: 309020.
2. Expected output should be: 3.
--------------------------------
1. User can input a very long integer. For example: 6505600560501015606400056140065510145610651065169156505561065100560056
2. Expected output should be: 21.
Thanks in advance.
#include <iostream> #include <string> using namespace std; int main() { string s; //cout << "Enter a number: "; // uncomment This line if you want a prompt cin >> s; int count = 0; for (int i = 0; i < s.size(); ++i) { if (s[i] == '0') { ++count; } } cout << count << endl; return 0; }
Get Answers For Free
Most questions answered within 1 hours.