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
|
844 Discussions
|
Please Login in order to post a comment
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;
}
The right approach:-
}