Home Forums C Programming odd numbers Reply To: odd numbers

#3407
Humayan
Participant

could do:
 

#include 
int main ()
{
    int i , j , k , h;
    int sum = 0;
   
    cout << "enter 4 numbers:" << endl;
    cin >> i;
    cin >> j;
    cin >> k;
    cin >> h;
   
    if ( i % 2 != 0 )
    {
        sum += i;
    }
    if ( j % 2 != 0 )
    {
        sum += j;
    }
    if ( k % 2 != 0 )
    {
        sum += k;
    }
    if ( h % 2 != 0 )
    {
        sum += h;
    }
    cout << "sum of odds: " << sum << endl;
    return 0;
}