Inputing Integer Number in C Language
Posted by 
Ravi Kumar at Saturday, September 10, 2011
| Share this post: | 
The field specification for reading an integer number is:
                     %wd
     the percent sign(%) indicates that a conversion 
specification follows. W is an integer number,that specifies
the field width of the number to be read and d known as data
type character, indicates that the number to be read i in 
integer mode.
Example:      scanf("%2d %5d",&num1,&num2);
data line:       60        13456
      the value 60 is assigned to num1 and 13456 to num2.Input
data item must be separated by spaces,tab or new line. 
Punctuation mark do not count a separator.Various input format
ting options for reading integers are experimented with in the
program.
Program:  
        /*Reading integer number*/
        main()
        {
         int a,b,c,m,n;
         int i,j,k;
         printf("enter three integer numbers \n");
         scanf("%d%*d%d",&a,&b,&c);
         printf("%d%d%d\n\n",a,b,c);
         printf("enter two 4-integer numbers \n");
         scanf("%d%4d",&m,&n);
         printf("%d%d\n\n",m,n);
         printf("enter two integer numbers \n");
         scanf("%d%*d%d",&a,&m);
         printf("%d%d%d\n\n",a,m);
         printf("enter a nine digit numbers \n");
         scanf("%3d%4d%3d",&i,&j,&k);
         printf("%d%d%d\n\n",i,j,k);
         printf("enter two three digits \n");
         scanf("%d%*d%d",&m,&n);
         printf("%d%d%d\n\n",m,n);
        }
Output:           
enter  three  numbers
                  1   2   3
                  1   3  -3577
                  enter  two 4-digit numbers
                  2345          6417
                  23  45
                  enter two integers
                   44        66
                   4321     44     
                  enter  a nine digit number
                   123456789
                   66  1234 567
                  enter two three digit numbers
                   123   456
                   89    123







