UMBC CS 201, Fall 06
UMBC CMSC 201
Fall '06

CSEE | 201 | 201 F'06 | lectures | news | help

scanf

Our first program using scanf simply reads in an integer and a double and prints them out.

The Program

/********************************************* ** File: scanf.c ** Author: R. Chang ** Modified by: S. Evans ** Date: 3/5/04 ** Section: 01XX & 02XX ** EMail: bogar@cs.umbc.edu ** ** This program demonstrates the use ** of the scanf function. **********************************************/ #include <stdio.h> int main ( ) { int n ; double x ; printf("Enter an integer: ") ; scanf("%d", &n) ; printf("Enter a double: ") ; scanf("%lf", &x) ; printf("n = %d, x = %f\n", n, x) ; return 0; }

The Sample Run

linux3[84] % a.out Enter an integer: 34 Enter a double: 342.123 n = 34, x = 342.123000 linux3[85] % !a a.out Enter an integer: 34 Enter a double: 34e12 n = 34, x = 34000000000000.000000 linux3[86] % !a a.out Enter an integer: 34e12 Enter a double: n = 34, x = 0.000000 linux3[87] % !a a.out Enter an integer: bbb bbb Enter a double: n = -1073743084, x = 20413874176.000061 linux3[88] %


CSEE | 201 | 201 F'06 | lectures | news | help

Tuesday, 22-Aug-2006 07:14:18 EDT