Math, asked by dadhichraissa973, 1 year ago

write a program to find the sum of even and odd numbers in an array.

Answers

Answered by Tusharch8911
4
Hey dear,

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

/* C Program to find Sum of Even and Odd Numbers in an Array */

#include<stdio.h>

int main()

{

int Size, i, a[10];

int Even_Sum = 0, Odd_Sum = 0;

printf("\n Please Enter the Size of an Array : ");

scanf("%d", &Size);

printf("\nPlease Enter the Array Elements\n");

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

{

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

}

  

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

{

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

   {

Even_Sum = Even_Sum + a[i];

   }

   else

   {

Odd_Sum = Odd_Sum + a[i];

   }

}

  

printf("\n The Sum of Even Numbers in this Array = %d ", Even_Sum);

printf("\n The Sum of Odd Numbers in this Array = %d ", Odd_Sum);

return 0;

}

Hope it will help u...
Answered by Soñador
2

Answer:

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int a,s=0,s1=0;

for(int i=0;i<10;i++)

{

cout<<"\nEnter any number";

cin>>a[i];

}

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

{

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

s=s+a[i];

else

s1=s1+a[i];

}

cout<<"\nSum of odd numbers is<<s1;

cout<<"\nSum of even numbers is<<s;

getch();

}

Similar questions