Mr. Hari has bought 10 items from the shop. He has stored the price of all the items in an array. Help
Mr. Hari to print the sum of the even items in the array
#include <stdio.h>
#include <stdlib.h>
int main()
{
int sumEvenItems=0;
int i;
int items[]={5,8,9,4,2,3,69,5,6,9};
for(i=0;i<10;i++){
if(items[i]%2==0){
sumEvenItems+=items[i];
}
}
printf("The sum of the even items in the array: %d\n\n",sumEvenItems);
getchar();
return 0;
}
Comments
Leave a comment