- This topic has 1 reply, 2 voices, and was last updated 16 years, 5 months ago by .
Viewing 1 reply thread
Viewing 1 reply thread
- The forum ‘C Programming’ is closed to new topics and replies.
Home › Forums › C Programming › odd numbers
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.
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 /> } |