c printf and scanf

C printf() function:

The printf() function is an inbuilt library function in C language, which is used for output, i.e, to print a given statement on the console. The printf() function is defined in stdio.h (header file) in C library.

Syntax:

printf(“format string”,argument_list);

  • Format string: It is a mandatory parameter which takes value as
  • Argument List: It is also a mandatory parameter which includes all the variables that are required to print.

C scanf() function:

The scanf() function is an inbuilt library function in C language, which is used for input, i.e, to  read the input data from the console. The scanf() function is also defined in stdio.h (header file) in C library.

Syntax:

scanf(“format string”,&argument_list);

  • Format string: It is a mandatory parameter which takes value as
  • & (Ampersand): It is added just before the variable name which represents that the data need to be feeded.
  • Argument List: It is also a mandatory parameter which includes all the variables in which the input data need to be feed.

 

Example:

#include<stdio.h>
 
void main()
{
int a, b;
printf ("Enter two numbers: ");
scanf ("%d, %d",&a,&b);
printf("Sum of x+y = %i", a+b);
}

Output

Enter two numbers: 2,3             
Sum of x+y = 5