Write C++ program that prints all the values of a variable called i that are multiple of 2 and less than 40. Set i =1
//Program to prints all the values of a variable called i
//that are multiple of 2 and less than 40. Set i =1
// the preprocessing directives
#include <iostream>
using namespace std;
int main() {
// declare and initialize variable
int i=1;
// loop i=1 and less than 40
for(i=1; i<40; i++)
if(i%2==0) // if multiple of 2
cout<<i<<' '; // print i
cout<<endl;
return 0;
}
Comments