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.

#include<iostream>#include<cstdio>usingnamespacestd;intmain(){// Complete the code.inta,b;intn=0;stringintMap[9]={"one","two","three","four","five","six","seven","eight","nine"};cin>>a>>b;if((a<=9)&&(b<=9)){for(n=a;n<=b;n++){cout<<intMap[n-1]<<endl;}}elseif((a<=9)&&(b>9)){for(n=a;n<=9;n++){cout<<intMap[n-1]<<endl;}for(n=10;n<=b;n++){if(n%2==0){cout<<"even"<<endl;}else{cout<<"odd"<<endl;}}}else{for(n=a;n<=b;n++){if(n%2==0){cout<<"even"<<endl;}else{cout<<"odd"<<endl;}}}return0;}

//Compares the values of a, b with 9 and if values <= 9 then//Prints all values from 'a' uptill 'b' in string formatif((a<=9)&&(b<=9)){for(n=a;n<=b;n++){cout<<intMap[n-1]<<endl;}}//Compares the values of a, b with 9//And if the value of a <= 9 and value of b > 9 then....elseif((a<=9)&&(b>9)){//Prints all the values starting from 'a' uptill 9//in string format and then....for(n=a;n<=9;n++){cout<<intMap[n-1]<<endl;}//For values which are greater than 9 and <= to 'b'//Prints 'even' or 'odd' for themfor(n=10;n<=b;n++){if(n%2==0){cout<<"even"<<endl;}else{cout<<"odd"<<endl;}}}Hopethathelps.

for(n=10;n<=b;n++)
checking the value of n is less than b
if(n%2==0)
suppose the value of n you given is 10
if statement will find the remainder by using the modulus %
that is n%2
10%2 just divide the reminder will always be zero which means if its divisible by 2 it is even number..

you have a for loop and it start counting from 10 , after check the condition if n is inferior or egal to b , when it is true it increment the value of n ...
if n%2 == 0 , means if n is divisible by 2 , he will display even
I hope it helps you :-)

can u please explain the string type in C++ .I searched it over net but didn't got the satisfying result. According to me String is an array of char but you used it as a predefined data-type.how?

After your "else if", your "else" statement can be skipped. It will pass all tests cases without. Just saying...
Your code is great by the way and pass all tests cases anyway ;-)

## For Loop

You are viewing a single comment's thread. Return to all comments →

Great code, I like it.

Here is mine:

for(n=10;n<=b;n++){

if (n%2==0){ cout<<"even"<

why you have used intmap[n-1]

thank you so much...

for(n=10;n<=b;n++) checking the value of n is less than b if(n%2==0) suppose the value of n you given is 10 if statement will find the remainder by using the modulus % that is n%2 10%2 just divide the reminder will always be zero which means if its divisible by 2 it is even number..

you have a for loop and it start counting from 10 , after check the condition if n is inferior or egal to b , when it is true it increment the value of n ... if n%2 == 0 , means if n is divisible by 2 , he will display even I hope it helps you :-)

what is the use of String intMap[]

can u please explain the string type in C++ .I searched it over net but didn't got the satisfying result. According to me String is an array of char but you used it as a predefined data-type.how?

are you askin about its library file? If that is true,

## include

Love your code but arrays havent been introduced here yet! so why did u use it? Cant it be done without arrays?

After your "else if", your "else" statement can be skipped. It will pass all tests cases without. Just saying... Your code is great by the way and pass all tests cases anyway ;-)

Much simple, try this.

it helped

sir, can you explain in easy way, please

Unnecessarily making it so long and unreadable.

I think it is better than writing multiple "if-else" and one who can code can read it without any trouble.

what for the values when a and b both are greater than 9

pretty long one.

exactly wwhat i did nut there are slightly better codes available we wont need those many if else and for loops inside.