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
#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;
}
}
}
Comments
Leave a comment