PL1 Lecture 2 Library and Printf & Scanf Function
PL1 Lecture 2 Library and Printf & Scanf Function
List of topics,
Library of header files
Print function
Scan function
LIBRARY OF HEADER FILES
stdio.h C library to perform Input/Output operations (header)
string.h C Strings (header)
time.h C Time Library (header)
math.h C numerics library (header)
ctype.h Character handling functions (header)
assert.h C Diagnostics Library (header)
errno.h C Errors (header)
float.h Characteristics of floating-point types (header)
iso646.h ISO 646 Alternative operator spellings (header)
limits.h Sizes of integral types (header)
locale.h C localization library (header)
setjmp.h Non local jumps (header)
signal.h C library to handle signals (header)
stdarg.h Variable arguments handling (header)
stddef.h C Standard definitions (header)
stdlib.h C Standard General Utilities Library (header)
PRINTF() AND SCANF() FUNCTION IN C
printf() is used to display the output, e.g., to display panel.
int main(){
// a floating point variable.
float gpa = 3.99; Output:
My Gpa is 3.99
printf("My Gpa is 3.99\n"); My Gpa is 3.990000
printf("My Gpa is %f \n", gpa); My Gpa is 3.99
printf("My Gpa is %.2f \n", gpa);
return 0;
}
PRINTF() FUNCTION
int main(){
// variables of different types.
int no = 150;
float flt = 10.234;
double dbl = 20.123456;
char ch = 'A';
Output:
char str[24] = "This is my first
program"; Integer value: 150
Float value: 10.234000
Double value: 20.123456
// printing values of all the variables Character: A
printf("Integer value: %d\n" , no); String: This is my first program
printf("Float value: %f \n", flt);
printf("Double value: %lf \n", dbl);
printf("Character: %c \n", ch);
printf("String: %s \n" , str);
return 0;
}
PRINTF() FUNCTION
Output:
My name is Rahim.
I am teaching 'C programming'
SCANF() FUNCTION
int main(){
// a floating point variable. Output:
float gpa; Enter your gpa: 3.887
printf("Enter your gpa:\t"); Your gpa is: 3.887000
scanf("%f", &gpa);
int main(){
char name [20]; float gpa;
Output:
printf("Enter your name:\t");
Enter your name: Rahim
scanf("%s", &name); Enter your gpa: 3.98
Welcome Rahim, your gpa is:
printf("Enter your gpa:\t"); 3.980000
scanf("%f", &gpa);
https://www-s.acm.illinois.edu/webmonkeys/book/c_guide/