We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- C++
- Introduction
- Conditional Statements
- Discussions
Conditional Statements
Conditional Statements
Sort by
recency
|
846 Discussions
|
Please Login in order to post a comment
include
using namespace std;
string ltrim(const string &); string rtrim(const string &);
int main() { string n_temp; getline(cin, n_temp);
}
string ltrim(const string &str) { string s(str);
}
string rtrim(const string &str) { string s(str);
}
Sol using switch:
Exercise was ment to teach conditional statements, so I used them all without anything else which would be (cheating in my opinion).
I changed input type
int n
tounsigned int n
because of given constraints. It says that there can't be negative numbers, so we should use a proper type.I have put
Greater than 9
condition before all other because it is more likely that user will input greater number than 9. This way we prevent 9 statement checks which will make code execute faster in most cases.This is the code:
include
using namespace std; int main(){ int n; cin>>n;
}