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
|
799 Discussions
|
Please Login in order to post a comment
include
using namespace std;
int main() { int n; cin >> n; if(n<=9) { switch(n) { case 1:cout << "one"; break; case 2:cout << "two"; break; case 3:cout << "three"; break; case 4:cout << "four" ; break; case 5:cout << "five" ; break; case 6:cout << "six" ; break; case 7:cout << "seven" ; break; case 8:cout << "eight"; break; case 9:cout << "nine"; break; } } else if (n>9) { cout << "Greater than 9"<
return 0; }
string s[9] = {"one","two","three","four","five","six","seven","eight","nine"};
EASY SOLUTION works 100%
Using Key Value pairs with OR gate condition,
int main(){ map numbers; int a ; cin >> a ; numbers[1] = "one"; numbers[2] = "two"; numbers[3] = "three"; numbers[4] = "four"; numbers[5] = "five"; numbers[6] = "six"; numbers[7] = "seven"; numbers[8] = "eight"; numbers[9] = "nine"; if (numbers.find(a) != numbers.end()){ cout << numbers[a];
}
else if ((numbers.find(a) == numbers.end()) || (a > 9) ) { cout << "Greater than 9"; }
}
Create a hash table to solve the problem.
I didn't get this what they had done. If somebody knows please explain.The code by hackerrank is pasted below:
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);
}