Professional Documents
Culture Documents
Lab Activity 3
Lab Activity 3
COMPUTER PROGRAMMING
BIC10204
Learning Outcome : At the end of this lab session, students are able to know and understand the
concept of input/output operation in C programming
Duration : 2 hours
Explanation :
Input and output operation in a C program involves the use of printf() and scanf()function.
The printf() function is used to prompt any message in order to trigger user respond for entering
a certain data. Whenever a program needs to read the data entered by user, scanf()function is
used. It works by reading the input data and store it in computer memory. Besides these two
functions, we can also use other I/O functions such as gets() and puts(), getchar() and
putchar() and lastly getch() and putch(). Below is example of a C program that performs
input and output operation using printf() and scanf()function.
#include <stdio.h>
int main()
{ Ampersand symbol (&) for location reference
char name[20];
int mark;
} Placeholder (%d)
Print list – can be
variable/constant/expression/function
Placeholder symbols to remember are stated below:
%d Integer
%f Decimal
%c Character
%s String
1.
1
a.
#include <stdio.h>
void main()
{
int num;
char character;
b.
#include <stdio.h>
int main()
{
char character;
c.
#include <stdio.h>
int main()
{
char name[20];
2
2. Write a complete program following the algorithm given below.
4. Develop a simple subject registration system. The program requires user to enter student’s full
name, I/C number, matric number, subject code and subject name. Then the program will print out
all the data that has been entered on the screen.