Answer to Question #197601 in C++ for she

Question #197601

a) Write a program in C++ using repetition that is capable of displaying how many numbers from 0 to 100 that is divisible by 2 and 5.


b) Write a program in C++ using repetition that is able to determine and display the largest and the smallest number among any number of integers entered by the user.


1
Expert's answer
2021-05-23T14:39:03-0400

a) Write a program in C++ using repetition that is capable of displaying how many numbers from 0 to 100 that is divisible by 2 and 5.

#include <iostream>

using namespace std;

int main() 
{
  int count = 0;
  for (int i = 0; i < 100; i++ )
    // if a number is divisible by 2 and 5, it is divisible by 10
    if (i % 2 == 0 and i % 5 == 0) { // or i % 10 == 0
      count++;
    }
  }
  cout << count << endl;
  return 0;  
}

b) Write a program in C++ using repetition that is able to determine and display the largest and the smallest number among any number of integers entered by the user.

#include <iostream>

using namespace std;

int main()
{
  int min = INT_MAX, max = INT_MIN;
  int value;
  while (cin >> value) {
    if (min > value) min = value;
    if (max < value) max = value;
  }
  cout << "min=" << min << endl;
  cout << "max=" << max << 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