C Program to Sum of Even and Odd Numbers in an Array

C Program to Sum of Even and Odd Numbers in an Array

C program to sum of even and odd numbers in an array; Through this tutorial, we will learn how to calculate or find sum of even and odd numbers in an array using in c programs.

Programs and Algorithm to Sum of Even and Odd Numbers in an Array in C

  • C Program to Sum of Even and Odd Numbers in an Array using For Loop
  • C Program to Sum of Even and Odd Numbers in an Array using While Loop
  • C Program to Sum of Even and Odd Numbers in an Array using Function

C Program to Sum of Even and Odd Numbers in an Array using For Loop

/* C Program to find Sum of Even and Odd Numbers in an Array */
#include<stdio.h>
 
int main()
{
 int Size, i, a[10];
 int Even_Sum = 0, Odd_Sum = 0;
 
 printf("\n Please Enter the Size of an Array : ");
 scanf("%d", &Size);
 
 printf("\nPlease 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("\n The Sum of Even Numbers in this Array = %d ", Even_Sum);
 printf("\n The Sum of Odd Numbers in this Array = %d ", Odd_Sum);
 return 0;
}

The output of the above c program; as follows:

Please Enter the Size of an Array : 5
Please Enter the Array Elements
1 2 3 4 5
The Sum of Even Numbers in this Array = 6 
 The Sum of Odd Numbers in this Array = 9 

C Program to Sum of Even and Odd Numbers in an Array using While Loop

/* C Program to find Sum of Even and Odd Numbers in an Array */
#include<stdio.h>
int main()
{
 int Size, i, j = 0, a[10];
 int Even_Sum = 0, Odd_Sum = 0;
 
 printf("\n Please Enter the Size of an Array : ");
 scanf("%d", &Size);
 
 printf("\nPlease Enter the Array Elements\n");
 for(i = 0; i < Size; i++)
 {
      scanf("%d", &a[i]);
 } 
 while(j < Size)
 {
   if(a[j] % 2 == 0)
   {
 	Even_Sum = Even_Sum + a[j];
   }
   else
   {
 	Odd_Sum = Odd_Sum + a[j];
   }
   j++;
 } 
 printf("\n The Sum of Even Numbers in this Array = %d ", Even_Sum);
 printf("\n The Sum of Odd Numbers in this Array = %d ", Odd_Sum);
 return 0;
}

The output of the above c program; as follows:

Please Enter the Size of an Array : 5
Please Enter the Array Elements
1 5 8 9 10
The Sum of Even Numbers in this Array = 18 
 The Sum of Odd Numbers in this Array = 15 

C Program to Sum of Even and Odd Numbers in an Array using Function

/* C Program to Count Even and Odd Numbers in an Array */
#include<stdio.h>

int CountEvenNumbers(int a[], int Size);
int CountOddNumbers(int a[], int Size);

int main()
{
 int Size, i, a[10];
 int Even_Count = 0, Odd_Count = 0;
 
 printf("\n Please Enter the Size of an Array : ");
 scanf("%d", &Size);
 
 printf("\nPlease Enter the Array Elements :  ");
 for(i = 0; i < Size; i++)
 {
      scanf("%d", &a[i]);
 }
 
 Even_Count = CountEvenNumbers(a, Size);
 Odd_Count = CountOddNumbers(a, Size);
  
 printf("\n Total Number of Even Numbers in this Array = %d ", Even_Count);
 printf("\n Total Number of Odd Numbers in this Array = %d ", Odd_Count);
 return 0;
}
int CountEvenNumbers(int a[], int Size)
{
  int i, Even_Count = 0;
  printf("\n List of Even Numbers in this Array: ");

  for(i = 0; i < Size; i ++)
  {
     if(a[i] % 2 == 0)
     {
 	printf("%d  ", a[i]);
 	Even_Count++;
     }
   }
   return Even_Count;
}
int CountOddNumbers(int a[], int Size)
{
  int i, Odd_Count = 0;
  printf("\n List of Odd Numbers in this Array: ");

  for(i = 0; i < Size; i ++)
  {
     if(a[i] % 2 != 0)
     {
 	printf("%d  ", a[i]);
 	Odd_Count++;
     }
   }
   return Odd_Count;
}

The output of the above c program; as follows:

Please Enter the Size of an Array : 5
Please Enter the Array Elements :  10 5 25 30 40
List of Even Numbers in this Array: 10  30  40  
 List of Odd Numbers in this Array: 5  25  
 Total Number of Even Numbers in this Array = 3 
 Total Number of Odd Numbers in this Array = 2 

Recommended C Programs

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published. Required fields are marked *