INPUT STATEMENT is used to input a single character or a sequence of characters from the keyboard. Types of input statement:Getch = A function used to input a single character from the keyboard without echoing the character on the monitor. Syntax: getch();
Example: ch = getch();Getche = A function used to input a single character from the keyboard, the character pressed echoed on the monitor, line the READLN in PASCAL Syntax: getche();
Example: ch = getche();Getchar = A function used to input a single character from the keyboard, the character pressed echoed on the monitor terminated by pressing Enter key. Syntax: getchar();
Example: ch = getchar();Gets = A function used to input a single character from the keyboard, spaces are accepted, terminated by pressing enter key. Syntax: gets();
Example: gets(ch);Scanf = A 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 spacebar. Syntax: gets();
Example: gets(ch);
OUTPUT STATEMENT is used to display the argument list or string on the monitor. Types of output statement:Puts = A function used to display the argument list or string on the monitor. It does not need the help of the control string codes. Syntax: puts();
Example: puts(“hello”);
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.
%c – used for single char in C
scanf(“%c”, &ch); printf(“%c”, ch);
%d – decimal number (whole number)
scanf(“%d”,&num); printf(“%d”,num);
%e – scientific notation / exponential form
scanf(“%e”, &result); printf(“%e”, result);
%f – number with floating or decimal point
scanf(“%f”,&pesos); printf(“%f”,pesos);
%o – octal number
scanf(“%o”, &valuet); printf(“%o”, value);
%s– string of characters
scanf(“%s”,&str); printf(“%s”,str);
%u – unsigned number
scanf(“%u”, &value); printf(“%u”, value);
%x– hexadecimal numbers
scanf(“%x”,&value); printf(“%x”,value);
%X – capital number for hexadecimal number
scanf(“%X”, &nos); printf(“%X”, nos);
%%– print a percent sign
scanf(“%%”,&value); printf(“%%”,value);
List of commonly used escape sequence:\\ - prints backslash
\’ – prints single quotes
\” – prints double quotes
\? – prints question mark
\n - newline
A function gotoxy is used to send the cursor to the specified location. Syntax: gotoxy(x,y);
Example: gotoxy(5,10);
/*y is assigned a numeric literal*/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;