Write a C Program to compute the sum of even numbers and the sum of odd numbers using a function.

#include<stdio.h>
#include<conio.h>
void sumfun(int a[],int n);
void main()
{
    int a[15],n,i;
    clrscr();
    printf("\nHow many number of terms?");
    scanf("%d",&n);
    printf("Enter the elements in the list");
    for(i=0;i<5;i++)
    scanf("%d",&a[i]);
    sumfun(a,n);
    getch();
}
void sumfun(int a[],int n)
{
   int i,osum=0,esum=0;
   for(i=0;i<n;i++)
   if(a[i]%2==0)
     esum=esum+a[i];
     else
       osum=osum+a[i];
       printf("esum is %d",esum);
       printf("\nosum is %d",osum);

}

No comments:

Post a Comment