Program to Find the Maximum of the Sum of the Even and Odd Numbers in an Array Using C Programming
#include<stdio.h>
void fun(int a[],int n);
int main()
{
int n;
int i;
int a[100];
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
fun(a,n);
return 0;
}
void fun(int a[],int n)
{
int i;
int oddsum=0;
int evensum=0;
int max=0;
for(i=0;i<n;i++)
{
if(a[i]%2==0)
{
evensum+=a[i];
}
else
{
oddsum+=a[i];
}
}
if(evensum>oddsum)
{
max=evensum;
printf("%d",max);
}
else if(oddsum>evensum)
{
max=oddsum;
printf("%d",max);
}
else
{
max=evensum;
printf("both are equal max: %d",max);
}
}
output:
-------
10
1 2 3 4 5 6 7 8 9 10
30
No comments:
Post a Comment