Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

find the sum of +ve even numbers and -ve odd numbers from the users input if input is 0 stop the process

0 votes
asked Dec 6, 2019 by anonymous

3 Answers

0 votes
answered Dec 8, 2019 by Mayank Singh (200 points)

  1. #include <stdio.h>
  2. void main()
  3. {
  4.     int i, num, odd_sum = 0, even_sum = 0;
  5.     printf("Enter the value of num\n");
  6.     scanf("%d", &num);
  7.     for (i = 1; i <= num; i++)
  8.     {
  9.         if (i % 2 == 0)
  10.             even_sum = even_sum + i;
  11.         else
  12.             odd_sum = odd_sum + i;
  13.     }
  14.     printf("Sum of all odd numbers  = %d\n", odd_sum);
  15.     printf("Sum of all even numbers = %d\n", even_sum);
  16. }
0 votes
answered Dec 12, 2019 by Khabibullah (140 points)
#include<bits/stdc++.h>
using namespace std ;
int main(){
    int n , i , a=0 , b=0 ;
    cin>> n ;
    if( n != 0 ){
        for( i=0 ; i<=n ; i++ ){
            if( i%2==0 ){
                a = a + i ;
             }else if( i%2==1 ){
              b = b + i ;
            }
        }
        cout<< a << endl << b ;
    }else
        cout<< endl ;
}
0 votes
answered Feb 28, 2020 by Mohammad Danish
#include<iostream>
int main()
{
    int eve = 0;
    int odd = 0;
    int num = 1;
    std::cout << "Enter the Number: ";
    std::cin >> num;
    if (num % 2 == 0)
        eve += num;
    else
        odd -= num;
    while (num != 0)
    {
        std::cout << "\nEnter the number: ";
        std::cin >> num;
        if (num % 2 == 0)
            eve += num;
        else
            odd -= num;
    }
    if (num == 0)
        return 0;
    std::cout << "\nSUM OF +ve EVEN: " << eve;
    std::cout << "\nSUM OF -ve ODD: " << odd;
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...