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

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including 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. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

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