Printf & Scanf
- printf() and scanf() functions are inbuilt library functions in C programming language which are available in C library by default. These functions are declared and related macros are defined in “stdio.h” which is a header file in C language.
- We have to include “stdio.h” file as shown in below C program to make use of these printf() and scanf() library functions in C language.
. PRINTF() FUNCTION IN C LANGUAGE:
- In C programming language, printf() function is used to print the “character, string, float, integer, octal and hexadecimal values” onto the output screen.
- We use printf() function with
%d
format specifier to display the value of an integer variable. - Similarly
%c
is used to display character,%f
for float variable,%s
for string variable,%lf
for double and%x
for hexadecimal variable. - To generate a newline,we use “\n” in C printf() statement.
C language is case sensitive. For example, printf() and scanf() are different from Printf() and Scanf(). All characters in printf() and scanf() functions must be in lower case.
EXAMPLE PROGRAM FOR C PRINTF() FUNCTION:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
#include <stdio.h>
int main()
{
char ch = 'A';
char str[20] = "Clanguage";
float flt = 10.234;
int no = 150;
double dbl = 20.123456;
printf("Character is %c \n", ch);
printf("String is %s \n" , str);
printf("Float value is %f \n", flt);
printf("Integer value is %d\n" , no);
printf("Double value is %lf \n", dbl);
printf("Octal value is %o \n", no);
printf("Hexadecimal value is %x \n", no);
return 0;
} |
Comments
Post a Comment