Computer Science, asked by harishvermabaq, 1 year ago

( C++ QUESTION)
Write a program using switch case to enter 5 numbers and calculate average of 5 numbers or to find how many are even number or to find the product of odd numbers.

Answers

Answered by kvnmurty
2
#include <iostream>
using namespace std;
int main() {
    int n, i, evencount = 0, oddcount=0;
    int oddproduct= 1, sum=0;

    for (i=0;i<5;i++) {
       cin >> n;
       sum += n;
       switch (n%2) {
          case 0:
              evencount++;
              break;
          case 1:
              oddcount++;
              oddproduct *= n;
              break;
           }
      }
      cout << "Average =" << sum/5 << "\n" ;
      cout << evencount << " even numbers are there." << "\n" ;
      cout << "product of odd numbers is " << oddproduct << "\n" ;
     return 0;
}


kvnmurty: :-)
harishvermabaq: Thank you sir
Similar questions