Home › Forums › C Programming › odd numbers › Reply To: odd numbers
July 21, 2008 at 12:21 pm
#3407
Humayan
Participant
could do:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #include <br /> int main ()<br /> {<br /> int i , j , k , h;<br /> int sum = 0;<br /> <br /> cout << "enter 4 numbers:" << endl;<br /> cin >> i;<br /> cin >> j;<br /> cin >> k;<br /> cin >> h;<br /> <br /> if ( i % 2 != 0 )<br /> {<br /> sum += i;<br /> }<br /> if ( j % 2 != 0 )<br /> {<br /> sum += j;<br /> }<br /> if ( k % 2 != 0 )<br /> {<br /> sum += k;<br /> }<br /> if ( h % 2 != 0 )<br /> {<br /> sum += h;<br /> }<br /> cout << "sum of odds: " << sum << endl;<br /> return 0;<br /> } |