Home Forums C Programming C program that reads an integer odd/even?

Viewing 2 reply threads
  • Author
    Posts
    • #2163
      SilviaJamieson
      Participant

      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

    • #3488
      GWILouisaxwzkla
      Participant

      could do


      /****************************************************************
      * File Name : c:programstempCG.cpp
      * Date : December,7,2008
      * Comments : new project
      * Compiler/Assembler :
      * Modifications :
      *
      *
      *
      *
      *
      * Program Shell Generated At: 2:39:41 p.m.
      =-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/


      #include < stdio.h >
      //#include < string.h >
      //#include < conio.h >
      //#include < math.h >
      //#include < iomanip >
      //#include < ctype.h >



      //main function ******************************

      int main ( )
      {

      int number;

      printf ( "enter a number: " );
      scanf ( "%i" , & number );

      if ( number % 2 == 0 )
      printf ( "The number is even n " );
      else
      printf ( "Then number is odd n " );


      return 0 ;
      }



    • #3489
      SilviaJamieson
      Participant

      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

Viewing 2 reply threads
  • The forum ‘C Programming’ is closed to new topics and replies.