Answer to Question #262301 in C++ for Urooj

Question #262301

Using a for loop, write a programme that prints all values between 20 and 24. Then using an if-else statement and the modulus operator, modify your program to add the word "odd" or "even" to each value to show if it is odd or even.


Expected Output:


20-even


21-odd


22-even


23-odd


24-even


1
Expert's answer
2021-11-07T10:15:41-0500
#include <iostream>  
  
using namespace std; 
int main(){
	for(int i=20; i<=24; i++){
		if(i%2==0){
			cout<<i<<"-even"<<endl;
		}
		else{
			cout<<i<<"-odd"<<endl;
		}
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS