Write a program that prints:
(a) all the even numbers between 1 and 100.
(b) all the odd numbers between 1 and 100.
(c) all multiples of 3 between 1 and 100.
#include <iostream>
using namespace std;
int main(){
cout<<"All even numbers between 1 and 100\n";
for(int i = 1; i <= 100; i++){
if(i % 2 == 0){
cout<<i<<" ";
}
}
cout<<"\n\nAll odd numbers between 1 and 100\n";
for(int i = 1; i <= 100; i++){
if(i % 2 !=0){
cout<<i<<" ";
}
}
cout<<"\n\nAll multiples of 3 between 1 and 100\n";
for(int i = 1; i <= 100; i++){
if(i % 3 == 0){
cout<<i<<" ";
}
}
return 0;
}
Comments
Leave a comment