Tuesday 22 January 1985

Printf() & Scanf() function


printf() and scanf() functions are used for input and output and it  is inbuilt library function define in #include<stdio.h> header file.

Printf() function:
  1. Printf() function is used to print message / argument / output.
  2. It print given argument.
Printf() function Syntax:
  1. printf("format string",argument_list);  

The format string can be %d (integer), %c (character), %s (string), %f (float) etc.


Scanf() function:
  1. Scanf() function is used to read data from user.
  2. Scanf() function is used for input.
Scanf() function Syntax:
  1. scanf("format string",argument_list);  

The format string can be %d (integer), %c (character), %s (string), %f (float) etc.


Example
  1. #include<stdio.h>    
  2. int main(){    
  3. int marks;    
  4. printf("Enter a Marks:");    
  5. scanf("%d",&marks);    
  6. printf("You have enter marks is:%d ",marks);    
  7. }    

The scanf("%d",&marks) statement reads integer number from the console and stores the given value in number variable.
Share This
Previous Post
Next Post

0 Comments: