Home Forums C Programming odd numbers

Viewing 1 reply thread
  • Author
    Posts
    • #2116
      krjavia
      Participant

      write a c++ program that the will ask the user to encode four numbers and will determine the odd numbers and automatically get the total of those odd numbers encoded.

    • #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;
      }
Viewing 1 reply thread
  • The forum ‘C Programming’ is closed to new topics and replies.