Home › Forums › C Programming › C program that reads an integer odd/even?
- This topic has 2 replies, 2 voices, and was last updated 15 years, 10 months ago by SilviaJamieson.
- AuthorPosts
- December 5, 2008 at 3:34 am #2163SilviaJamiesonParticipant
Lab assignment 4 – Question 1.
Hi everyone,
I’m new to C++ programming and i am finding it a little bit confusing, any help would be great. :oops:
Write a C program that reads an integer number and then determines and prints whether it is odd or even number.
„ Use simplest form if statement
„ Use scanf function to read an integer input from keyboard
„ Use printf function to display the result• If it is odd number, display the message “? is an odd number”.
• If it is even number, display the message “? is an even number”
„ Hint : Use the remainder operator. An even number is a multiple of two. Any multiple of two leaves a
remainder of zero when divided by 2.Thanks for any help……daisy :P
- December 7, 2008 at 7:45 pm #3488GWILouisaxwzklaParticipant
could do
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647<br />/****************************************************************<br />* File Name : c:programstempCG.cpp<br />* Date : December,7,2008<br />* Comments : new project<br />* Compiler/Assembler :<br />* Modifications :<br />*<br />*<br />*<br />*<br />*<br />* Program Shell Generated At: 2:39:41 p.m.<br />=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/<br /><br /><br />#include < stdio.h ><br />//#include < string.h ><br />//#include < conio.h ><br />//#include < math.h ><br />//#include < iomanip ><br />//#include < ctype.h ><br /><br /><br /><br />//main function ******************************<br /><br />int main ( )<br />{<br /><br />int number;<br /><br />printf ( "enter a number: " );<br />scanf ( "%i" , & number );<br /><br />if ( number % 2 == 0 )<br />printf ( "The number is even n " );<br />else<br />printf ( "Then number is odd n " );<br /><br /><br />return 0 ;<br />}<br /><br /><br /><br /> - December 8, 2008 at 2:58 pm #3489SilviaJamiesonParticipant
Thank you, dman
I can understand it when someone lays it out nice and simple as you have done. I really appreciate the assistance, and I feel so much better now, thanks again…. :D
- AuthorPosts
- The forum ‘C Programming’ is closed to new topics and replies.