Login to ask a question from C Programs on integers

C Program to Calculate the Sum of Odd & Even Numbers:

This is a C program to find the sum of odd and even numbers from 1 to N.

Problem Description

The program takes the number N and finds the sum of odd and even numbers from 1 to N.

Problem Solution

  • Take the number N upto which we have to find the sum as input.

  •  Using for loop take the elements one by one from 1 to N.

  • Using if,else statements separate the element as even or odd.

  • Add the even and odd numbers separately and store it in different variables.

  • Print the sum separately and exit.

Program/Source Code

#include

 

void main()

{

    int i, num, odd_sum = 0, even_sum = 0;

<....
Show More
Previous Question Next Question
🔗

Similar Questions

From C Programs on integers · C programming

View All
WhatsApp