Saturday, September 20, 2008

LEARNINGS OF THE WEEK (TAGARO)

INPUT AND OUTPUT STATEMENTS
BY: Sharra Mae S. Tagaro IV- Rizal
Input Statement
A statement used to input a single character or a sequence of characters from the keyboard.
Types of Input Statement

1.)getch
-A function used to input a single character from the keyboard without echoing the character on the monitor.
Syntax: getch();
o2.)getche
o-A function used to input a single character from the keyboard, the character pressed echoed on the monitor, line the READLN in PASCAL
oSyntax: getche();
o3.)getchar
o-A function used to input a single character from the keyboard, the character pressed echoed on the monitor terminated by pressing Enter key.
oSyntax: getchar();
o4.)gets
o-A function used to input a single character from the keyboard, spaces are accepted, terminated by pressing enter key.
oSyntax: gets();
o5.)scanf
oA function used to input a single character or sequence of characters from the keyboard, it needs the control string codes in able to recognized. Spaces are not accepted upon inputting. Terminated by pressing space bar.
oSyntax: gets();

Output Statement
A statement used to display the argument list or string on the monitor.
Types of Output Statement
1.)printf
-A function used to display the argument list on the monitor.
It sometimes needs the control string codes to help display the remaining argument on the screen.
Syntax: printf(“control string codes”, argument list)
o2.)putchar
o-A function used to display the argument list or string on the monitor. It is like overwriting a character.
oSyntax: putchar();
o3.)puts
o-A function used to display the argument list or string on the monitor. It does not need the help of the control string codes.
oSyntax: puts();

Format String and Escape Sequence
Format Specifiers
o-All format specifiers start with a percent sign (%) and are followed by a single letter indicating the type of data and how data are to be formatted.
List of Commonly Used format specifiers
1.)%c – used for single char in C
2.)%d – decimal number (whole number)
o3.)%e – scientific notation / exponential form
o
o
o4.)%f – number with floating or decimal point
o
o5.)%o – octal number
o
o
o6.)%s– string of characters
7.)%u – unsigned number
8.)%x– hexadecimal numbers
9.)%X – capital number for hexadecimal number
10.)%%– print a percent sign
List of Commonly used escape sequence
\\ - prints backslash
\’ – prints single quotes
\” – prints double quotes
\? – prints question mark
\n - newline
Gotoxy
-A function gotoxy is used to send the cursor to the specified location.
Syntax: gotoxy(x,y);
Example: gotoxy(5,10);
Inserting Comment
/*y is assigned a numeric literal*/
Assignment Statement
-It stores a value or a computational result in a variable. They are commonly used to perform most arithmetic operations in a program. It can also be used in printf() statement.
Syntax: variable = expression
Example: y=1;
Note:
A format specifier %.2f can be used to limit the output being displayed into two decimal places only.

No comments: