printf and scanf function

Example of printf() function

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.

#include<stdio.h>
int main ()
{
  printf("Hello World");
  return 0;
}

Output

Hello World

Example of scanf() function

scanf(“%d”, &b); The program will read in an integer value that the user enters on the keyboard (%d is for integers, as is printf, so b must be declared as an int) and place that value into b. The scanf function uses the same placeholders as printf: int uses %d.

#include<stdio.h>
int main ()
{

   int number;
   scanf("%d", &amp;number);
   printf("Value is = %d", number);
   return 0;
}

//enter input 10

Output

 Value is = 10

How to use printf function in c

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.

How to use scanf function in c

In the C programming language, scanf is a function that reads formatted data from stdin (i.e, the standard input stream, which is usually the keyboard, unless redirected) and then writes the results into the arguments given.

What is the use of scanf and printf in C programming?

To print is to produce output for the user to read, whereas to scan is to read input from the command line that the user types in. The f at the end stands for “formatted”. So both printf and scanf functions use codes within a format string to specify how output or input values should be formatted.