🔒 Closed Hello mga lods pwede pahelp c language

Status
Not open for further replies.

Elecit23

Eternal Poster
Write a function that separately sums the even indexed elements and odd indexed elements of an array of doubles. Each element of the array contributes to one of the two sums, depending on whether the index of the element is even or odd. Your function definition must have a heading like
this:
void sum(double b[ ])
{ int n;
double *sum_even;
double *sum_odd;
if (
:
}
 
This might help. Just use your familiarity with C language to convert this pseudocode.
Code:
function GetSum (Var[])
   set SumEven = 0
   set SumOdd = 0
   set size = Var.size
   set i =0
   while  i to size
     if var[i]%2 == 0
        SumEven += var[i]
     else
       SumOdd += var[i]
   endwhile
  
   print SumEven
   print SumOdd

endfunction
 
Status
Not open for further replies.

About this Thread

  • 1
    Replies
  • 263
    Views
  • 2
    Participants
Last reply from:
vhin le

Trending Topics

Online now

Members online
544
Guests online
1,177
Total visitors
1,721

Forum statistics

Threads
2,285,879
Posts
29,034,129
Members
1,218,699
Latest member
ttttttttttttttt
Back
Top