Answer to Question #172117 in C++ for sara

Question #172117

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


1
Expert's answer
2021-03-16T08:04:58-0400

//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;
}

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