Take numbers and display the sum of even numbers and odd numbers separately - C

Q. WAP to take numbers and display the sum of even numbers and odd numbers separately.
#BIT_FirstSem_2015_3No_8Marks_Solution
==> Code goes like this:

#include<stdio.h>
int main()
{
 int Size, i, a[10];
 int Even_Sum = 0, Odd_Sum = 0;

 printf("Please Enter the Size of an Array : ");
 scanf("%d", &Size);

 printf("Please 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("The Sum of Even Numbers in this Array = %d \n", Even_Sum);
 printf("The Sum of Odd Numbers in this Array = %d ", Odd_Sum);
 return 0;
}

Output:
















If you are using Turbo C++ IDE, then use conio.h in link section after stdio.h
and use getch(); to hold the output screen, just before the end of main function.
If you have any confusion regarding the program, please, comment below.
Happy Coding !
Thank you
Share on Google Plus

About Nepali Xoro

Interested in Information Technology, Spreading Knowledge for Nepalease IT Students."Loves Traveling", Listen Music and Surfing web.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment