- Prepare
- C++
- Introduction
- For Loop
- Discussions
For Loop
For Loop
+ 0 comments test case 0 is very misleading. Did not give clear directions
+ 0 comments I looked for solutions in here but I want to do it with only what informations they provided, so I did this.
#include <iostream> #include <cstdio> using namespace std; int main() { int a, b; cin >> a >> b; for ( int i = a; i <= b; i++) { if (i == 1) { cout << "one" << endl; } else if (i == 2) { cout << "two" << endl; } else if (i == 3) { cout << "three" << endl; } else if (i == 4) { cout << "four" << endl; } else if (i == 5) { cout << "five" << endl; } else if (i == 6) { cout << "six" << endl; } else if (i == 7) { cout << "seven" << endl; } else if (i == 8) { cout << "eight" << endl; } else if (i == 9) { cout << "nine" << endl; } else if ( i > 9 && i % 2 == 0 ) { cout << "even" << endl; } else { cout << "odd" << endl; } } return 0; }
+ 0 comments Testcases don't correspond to the description. Only the first (basic) testcase does. The description demands to supply integers "separated by a newline." whereas most testcases supply integers separated by a whitespace, so the first submission is likely doomed to fail if you try to carefully follow the description...
+ 0 comments why this code is unable to pass test case ??
include
include
using namespace std;
int main() {
string s[10]={"one","two","three", "four","five","six","seven","eigth","nine"}; int x,y ; cin>>x>>y; for(int i=x; i<=y;i++) { if(i>=1 && i<=9) { cout<9 && i%2==0) { cout<<"even"<
+ 0 comments What I wrote...
#include <iostream> #include <cstdio> #include <string> using namespace std; int main() { string s[] = {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; int a, b; cin >> a >> b; for(int i = a; i<=b; i++) { if (i<=9) { cout << s[i-1] << endl; } else if (i>9 && i%2==0) { cout << "even" << endl; } else { cout << "odd" << endl; } } return 0; }
Sort 1471 Discussions, By:
Please Login in order to post a comment