home *** CD-ROM | disk | FTP | other *** search
/ C by Discovery (4th Edition) / C_By_Discovery_4th_Edition.tar / C_By_Discovery_4th_Edition / _DISK_ / ch1 / input2.c < prev    next >
C/C++ Source or Header  |  2005-06-16  |  1KB  |  36 lines

  1. /*                    input2.c 
  2.  *
  3.  *   Synopsis  - A variable of type int is declared. The program
  4.  *               prompts for, accepts input of, and outputs an
  5.  *               integer value. The input and output are done 
  6.  *               three times - in decimal, hexadecimal, and 
  7.  *               octal.
  8.  *
  9.  *   Objective - Illustrates input and output of an integer 
  10.  *               value with scanf() and printf() using the 
  11.  *               conversion specifications %d for decimal, %x 
  12.  *               for hexadecimal, and %o for octal.
  13.  */
  14.  
  15. #include <stdio.h>
  16.  
  17. int main(void)
  18. {
  19.      int intvar;
  20.  
  21.      printf("Enter a decimal integer value: ");
  22.      scanf("%d", &intvar);
  23.                                                          /* Note 1 */
  24.      printf("The hexadecimal equivalent of %d is %x.\n", intvar, intvar);
  25.  
  26.      printf("Enter a hexadecimal integer value: ");
  27.      scanf("%x", &intvar);                               /* Note 2 */
  28.                                                          /* Note 3 */
  29.      printf("The value you entered was %o in octal.\n", intvar);
  30.  
  31.      printf("Enter an octal integer value: ");
  32.      scanf("%o", &intvar);                               /* Note 4 */
  33.      printf("The value you entered was %d in decimal.\n", intvar);
  34.      return 0;
  35. }
  36.