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
- For Loop
- Discussions
For Loop
For Loop
+ 0 comments int a, b, n; char str[10][20] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; cin >> a >> b; for (int n = a; n <= b; n++) { if (n >=1 & n <=9) { cout << str[n]<< endl; } else if ( n > 9) { if( n%2==0) { cout << "even" << endl; } else { cout << "odd" << endl; } } }
+ 0 comments #include <iostream> #include <cstdio> using namespace std; int main() { int a, b; cin >> a >> b; string num_word[11] = {"even","odd","one","two","three","four","five","six","seven","eight","nine"}; for(int i = a; i <= b; i++ ){ if(i >= 1 && i <= 9){ cout << num_word[i+1] << endl; }else{ cout << num_word[i%2] << endl; } } return 0; }
+ 0 comments int main() { int a,b; string numbers[9] = {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; cin >> a; cin >> b; for(int i = a; i<=b; i++){ if(i<=9){ printf("%s\n",numbers[i-1].c_str()); }else{ (i%2 == 0)? cout << "even\n" : cout << "odd\n"; } } return 0; }
+ 0 comments using namespace std; int main() { int n1 , n2 ; cin>>n1 ; cin >> n2 ; for (int n = n1 ; n<=n2; n++) { if(n==1){cout<<"one"<<endl;} else if(n==2){cout<<"two"<<endl;} else if(n==3){cout<<"three"<<endl;} else if(n==4){cout<<"four"<<endl;} else if(n==5){cout<<"five"<<endl;} else if(n==6){cout<<"six"<<endl;} else if(n==7){cout<<"seven"<<endl;} else if(n==8){cout<<"eight"<<endl;} else if(n==9){cout<<"nine"<<endl;} else if (n%2==0){ cout<<"even"<<endl; } else{ cout<<"odd"<<endl; } } return 0; }
+ 0 comments #include <iostream> #include <cstdio> using namespace std; void out(int n) { string num[9] = {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; if (n <= 9){ cout << num[n-1] << endl; } else if (n%2 == 0) { cout << "even" << endl; } else { cout << "odd" << endl; } } int main() { int a, b; cin >> a >> b; for (size_t i = a; i <= b; ++i) { out(i); } return 0; }
Load more conversations
Sort 1542 Discussions, By:
Please Login in order to post a comment