Use scanf() to read Numbers - C Language Basics

C examples for Language Basics:scanf

Introduction

To read an integer, use either the %d or %i specifier.

To read a floating-point number in either standard or scientific notation, use %e, %f, or %g.

C99 adds %a, which reads a floating-point number.

To use scanf( ) to read integers in either octal or hexadecimal, use the %o and %x format commands, respectively.

The %x can be in either upper - or lowercase.

The following program reads an octal and hexadecimal number:

Demo Code

#include <stdio.h>

int main(void)
{
   int i, j;/*from  w ww . j  a v  a2 s . com*/

   scanf("%o%x", &i, &j);
   printf("%o %x", i, j);

   return 0;
}

Result


Related Tutorials