printf() and scanf() functions in C Programming Examples

printf()  and scanf() functions

printf() function:

It prints the given data on the output screen.

Scanf() function:

It is used to read input from the keyboard.

Format Specifier of Each:

printf()-

printf("%d", 10);              - prints 10 on the output screen
printf("%f", num);            - prints the float value in variable num on the output screen
printf("%d and %d", a, b); - prints the value of the integers a and b on the output screen.

Suppose, if the value of a is 10 and the value of b is 20.  Then, the output for the below statement would be 10 and 20
printf("%d and %d", a, b);

scanf()-
Format specifier can be any of the following
%u  - unsigned int
%d  - int
%x  - hexadecimal
%o  - octal
%f  - float
%lf - double
%c  - char
%s  - string

scanf("%d", &v1); - inputs integer value
scanf("%x", &v2); - inputs hexadecimal value
scanf("%f", &v3); - inputs float value


Example:-

OUTPUT

Thanks For Visiting ...KeepVisiting๐ŸŒ๐ŸŒ๐ŸŒ๐ŸŒ๐ŸŒ

Comments

Popular posts from this blog

Implement Bouncing Ball Animation Using C Graphics

Walking Stickman -Using C graphics

Sine Wave - Using C Graphics