Program to declare a user defined array and print the sum of odd and even numbers.
#include <stdio.h>
#include <conio.h>
void main()
{
int a[10], i, sume=0, sumo= 0, n;
clrscr();
printf ("Enter the size of an array: ");
scanf ("%d", &n);
if (n<=10)
{
printf ("Enter the array data: ");
for (i=0;i<n;i++)
{
scanf ("%d", &a[i]);
}
for (i=0;i<n;i++)
{
if (a[i]%2==0)
sume = sume + a[i];
else
sumo = sumo + a[i];
}
printf ("Sum of odd number = %d and sum of even number = %d", sumo, sume);
}
else
printf ("\nSize is too large.");
getch();
}
#include <stdio.h>
#include <conio.h>
void main()
{
int a[10], i, sume=0, sumo= 0, n;
clrscr();
printf ("Enter the size of an array: ");
scanf ("%d", &n);
if (n<=10)
{
printf ("Enter the array data: ");
for (i=0;i<n;i++)
{
scanf ("%d", &a[i]);
}
for (i=0;i<n;i++)
{
if (a[i]%2==0)
sume = sume + a[i];
else
sumo = sumo + a[i];
}
printf ("Sum of odd number = %d and sum of even number = %d", sumo, sume);
}
else
printf ("\nSize is too large.");
getch();
}