Professional Documents
Culture Documents
Knowledge:
Understand various types of input and output syntaxes
Skill:
Develop a program to read/capture input and display output
FTSM
TK1913-C Programming
printf Function
TK1913-C Programming
printf Function
Example:
printf(TK1913 C Programming\n\n);
printf(List of Students\n);
printf(Ahmad bin Ali);
What does \n
mean?
TK1913
TK1913 C
C Programming
Programming
List of Students
_ of Students
List
Ahmad bin Ali _
_
TK1913-C Programming
printf Function
displayed
TK1913-C Programming
printf Function
Formats for displaying output values:
%s for string
%c for character
%d for integer
%f for float/double
TK1913-C Programming
Example:
Output format
Similar to:
printf( Display a string\n );
Output format
Example:
Output format
TK1913-C Programming
TK1913-C Programming
Example:
printf(%c %c %c, U, K, M);
U K M_
TK1913-C Programming
10
UKM_
TK1913-C Programming
11
TK1913-C Programming
12
%[<min_field_width>.<min_digit>]d
Example:
printf(Value is:%10.6d, 56342);
6 digits
Value is:
056342
10 characters
TK1913-C Programming
13
56342
Min 3 digits
10 characters
TK1913-C Programming
14
Value is:56342
Min 4 characters
5 characters
TK1913-C Programming
15
%[<min_field_width>.<decimal_places>]f
Example:
printf(Value is:%10.4f, 32.6784728);
4 digits
16
TK1913-C Programming
17
TK1913-C Programming
18
TK1913-C Programming
Min 5 characters
19
TK1913-C Programming
20
21
scanf Function
TK1913-C Programming
22
scanf Function
Example:
printf(Key-in a character and a number: );
scanf(%c%d, &char, &num);
printf(Character: %c\n, char);
char
m
?
num 103
?
23
scanf Function
Example:
#include <stdio.h>
day
16
?
month 12
?
void main( ) {
int day, month, year;
?
scanf(%d %d %d, &day, &month, &year); year 2005
printf(Day: %d, Month: %d, Year: %d, day, month,
year);
}
16 12 2005
Day: 16, Month: 12, Year: 2005_
TK1913-C Programming
24
Your Project
Any problem during lab and tutorial
sessions??
TK1913-C Programming
25
End of Lecture 5
Yes !! Thats all?
Whats next???
OPERATORS &
EXPRESSIONS on the way
TK1913-C Programming
26