Switch to full style
For C/C++ coders discussions and solutions
Post a reply

How to write C++ code that defines array of size 24 then;

Fri Apr 08, 2011 10:29 pm

Read the elements in the array

Find the average for the elements in array

Find the average of the even values in the array



Re: How to write C++ code that defines array of size 24 then;

Fri Apr 08, 2011 11:27 pm

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;
 


Post a reply
  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     -  
 balloon sort algorithm C++ implementation code-sorting array     -  
 quicksort algorithm implementation java code- array sorting     -  
 Bubble Sort Algorithm Java Implementation Code-Sorting Array     -  
 Array difference for associate array     -  
 What is the size of this Structure     -