Friday, 18 August 2017

Assignment 6 : Group B


Aim:Sum of all odd numbers and even numbers in the array.


Program: 
#include <stdio.h>
int  main()
{
  int i, num, oddsum = 0, evensum = 0,a[20];
     printf("Enter the value of num:\n");
    scanf("%d", &num);
    printf("Enter the array elemnts:");
    for(i=0;i<num;i++)
    {
        scanf("%d",&a[i]);
   }
    for (i = 0; i < num; i++)
    {
               if (a[i] % 2 == 0)
        {
            evensum = evensum + a[i];
        }
else
        {
                oddsum = oddsum + a[i];
        }
          }
    printf("Sum of all odd numbers  = %d\n", oddsum);
    printf("Sum of all even numbers = %d\n", evensum);

}

16 comments: