C Program to find Sum of Even and Odd Numbers in Given Range

C program to find the sum of even and odd numbers in the given range; Through this tutorial, we will learn how to find the sum of even and odd numbers in the given range in the c program with the help for loop and while loop.

Algorithm and Program to find Sum of Even and Odd Numbers in Given Range

Let’s use the following algorithm and program to find sum of even and odd numbers in given range in c:

  • Algorithm to find Sum of Even and Odd Numbers in Given Range
  • C Program to find Sum of Even and Odd Numbers in Given Range using For Loop
  • C Program to find Sum of Even and Odd Numbers in Given Range using While Loop

Algorithm to find Sum of Even and Odd Numbers in Given Range

Use the following algorithm to write a program to find the sum of even and odd numbers in a given range; as follows:

  • Step 1: Start Program
  • Step 2: Read the min and max number from user.
  • Step 3: Calculate sum of even and odd number using for loop or while loop.
  • Step 4: Print sum of even and odd number
  • Step 5: Stop Program

C Program to find Sum of Even and Odd Numbers in Given Range using For Loop

/* C Program to find Sum of Even and Odd Numbers from 1 to N */

#include<stdio.h>

int main()
{
  int i, Minimum, Maximum, Even_Sum = 0, Odd_Sum = 0;

  printf("\n Please Enter the Minimum Value:- ");
  scanf("%d", &Minimum);

  printf("\n Please Enter the Maximum Values :- ");
  scanf("%d", &Maximum);

  for(i = Minimum; i <= Maximum; i++)
  {
    if ( i%2 == 0 )
    {
       Even_Sum = Even_Sum + i;
    }
    else
    {
  	Odd_Sum = Odd_Sum + i;
    }
  }
  printf("\n The Sum of Even Numbers betwen %d and %d  = %d", Minimum, Maximum, Even_Sum);
  printf("\n The Sum of Odd Numbers betwen %d and %d  = %d", Minimum, Maximum, Odd_Sum);

  return 0;
}

The output of the above c program; as follows:

Please Enter the Minimum Value:- 20
Please Enter the Maximum Values :- 200
The Sum of Even Numbers betwen 20 and 200  = 10010
The Sum of Odd Numbers betwen 20 and 200  = 9900

C Program to find Sum of Even and Odd Numbers in Given Range using While Loop

/* C Program to find Sum of Even and Odd Numbers from 1 to N */

#include<stdio.h>

int main()
{
  int i, Minimum, Maximum, Even_Sum = 0, Odd_Sum = 0;

  printf("\n Please Enter the Minimum Value:- ");
  scanf("%d", &Minimum);

  printf("\n Please Enter the Maximum Values :- ");
  scanf("%d", &Maximum);
   i = Minimum;
    while(i<=Maximum){// loop use  to iterate 1 to num
        if(i%2==0)  //Check even number for sum
            Even_Sum=Even_Sum+i;
        else
            Odd_Sum=Odd_Sum+i;
             i++;
    }

  printf("\n The Sum of Even Numbers betwen %d and %d  = %d", Minimum, Maximum, Even_Sum);
  printf("\n The Sum of Odd Numbers betwen %d and %d  = %d", Minimum, Maximum, Odd_Sum);

  return 0;
}

The output of the above c program; as follows:

Please Enter the Minimum Value:- 20
Please Enter the Maximum Values :- 200
The Sum of Even Numbers betwen 20 and 200  = 10010
The Sum of Odd Numbers betwen 20 and 200  = 9900

Recommended C Programs

AuthorDevendra Dode

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 *