Write a program that reads a set of integers and then finds

Write a program that reads a set of integers and then finds and prints the sum of the even and odd integers.

Solution

I have kept the arr size as 100 so you can increase it accordingly.

#include <stdio.h>

int main()

{

    int arr[100], i, num, odd_sum=0, even_sum=0;

    printf(\"Enter the number of elements \ \");

    scanf(\"%d\", &num);

    printf(\"Enter the integers \ \");

    for (i = 0; i < num; i++)

    {

        scanf(\"%d\", &arr[i]);

    }

    for (i = 0; i < num; i++)

    {

        if (arr[i] % 2 == 0)

        {

            even_sum=even_sum+arr[i];

        }

    }
   printf(\"\ Sum Of Even Numbers Is %d \\t\",even_sum);
  

    for (i = 0; i < num; i++)

    {

        if (arr[i] % 2 != 0)

        {

            odd_sum=odd_sum+arr[i];

        }

    }
    printf(\"\ Sum Of Odd Numbers Is %d \\t\",odd_sum);

}

 Write a program that reads a set of integers and then finds and prints the sum of the even and odd integers.SolutionI have kept the arr size as 100 so you can

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site