Answer to Question #280658 in C for Tharu

Question #280658

Requirements:

(1) Write a program that declares a single-dimensional arrays named num.

(2) The numbers to be stored in num are 45, 86, 12, 37, 28, 113.

(3) Sum odds and evens separately.

(4) Finally, give the results that will be displayed on the screen.


1
Expert's answer
2021-12-20T09:54:31-0500
#include <stdio.h>

int main()
{
    int num[] = { 45, 86, 12, 37, 28, 113 };
    int size  = sizeof(num) / sizeof(num[0]);
    int sumOdds  = 0;
    int sumEvens = 0;

    int i;
    for(i = 0; i < size; ++i)
    {
        if(num[i] % 2 == 0)
        {
            sumEvens += num[i];
        }
        else
        {
            sumOdds += num[i];
        }
    }

    printf("Sum of odds is %d\nSum of evens is %d\n", sumOdds, sumEvens);

    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS