My code is experiencing the segementation fault even I tried to bound my input parameters as I believed that inputs are the reason of array out of bound errors.
Can someone please help me relaize where I am going wrong
CODE :
#include <iostream>
#include <cstdio>
using namespace std;
int main() {
string words[9] = {"one","two","three","four","five","six","seven","eight","nine"};
int numbers[9] = {1,2,3,4,5,6,7,8,9};
int input_a , input_b;
cin >>input_a>>input_b;
for( int i = input_a - 1 ; i <= 9;i++) {
cout << words[i]<<endl;
}
if(input_a % 2 == 0){
cout << "even"<< endl;
}
if (input_b % 2 == 0){
cout << "even" << endl;
}
else{
cout << "odd" << endl;
}
return 0;
}
Expected INPUT
8
11
Expected OUTPUT
eight
nine
even
oddtext
New contributor