Total members 11894 |It is currently Thu Nov 21, 2024 3:40 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Read the elements in the array

Find the average for the elements in array

Find the average of the even values in the array




Author:
Newbie
User avatar Posts: 6
Have thanks: 0 time

this is array creation in c++ , and getting the average of even number in this array .
Code:

    int x
[5]={3,4,5,6,6};
    
float evenAvg=0;
    
float eventCount=0;
    for(
int i=0;i<5;i++){
        if(
x[i]%2==0)
        {
          
evenAvg+=x[i];
          
eventCount++;

        }
    }
    
evenAvg/=eventCount;
 


_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

For this message the author DrRakha has received gratitude : sakorian
Post new topic Reply to topic  [ 2 posts ] 

  Related Posts  to : How to write C++ code that defines array of size 24 then;
 How to write a code for sorting array of 100 number in C++     -  
 Array size to zero     -  
 how to write code message to user before session will expire     -  
 Set image size as a percentage of the page size     -  
 Incomplete code for array sorting and merging     -  
 quicksort algorithm implementation java code- array sorting     -  
 balloon sort algorithm C++ implementation code-sorting array     -  
 Bubble Sort Algorithm Java Implementation Code-Sorting Array     -  
 Array difference for associate array     -  
 What is the size of this Structure     -  



cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com