Computer Science, asked by shreeparnagupta3, 1 month ago

in c++ wap to enter a number and print the average of even numbers it has using while loop programs​

Answers

Answered by anindyaadhikari13
1

CORRECT QUESTION.

  • Write a program in C++ that takes a number as input and print the average of even digits it has using while loop.

THE CO‎‎DE.

#include <iostream>

using namespace std;

int main() {

   int number,even_digit_counter=0;

   double average;

   cout<<"Enter a number: ";

   cin>>number;

   while(number!=0){

       int remainder=number%10;

       if(remainder%2==0){

           average+=remainder;

           even_digit_counter++;

       }

       number/=10;

   }

   average/=even_digit_counter;

   cout<<"Average of even digits of the number is: "<<average;

   return 0;

}

SAMPLE I/O.

> Enter a number: 1244

> Average of even digits of the number is: 3.33333

See attachment for verification.

Attachments:
Similar questions