Hi Guest 1 HomePage 1 Jobs 1 WalkIn 1Articles  

 :) Latest Topic
Introduction to C
History of C Language
C Variables
Variables Types in C
C Identifiers
C Operators
C Comments
ASCII Value C
Constants C
Features of C
Install C Language
Start C Program
Compilation in c
printf() and scanf()
C Data Types
C Keyword
Format Specifier C
Format Specifier part2
Escape Sequence C
Tokens in C
Boolean in C
What are literals?
 


  

 
printf() and scanf()
Question Posted on 14 Aug 2020

Home >> Tutorial >> C Language >> printf() and scanf()


printf() and scanf()
Most common used functions in C language is printf() and scanf(). Both of these are inbuilt library functions which is defined in stdio.h which is header file. And printf() and scanf() function are used for input and output in C Language.

printf() function


We used printf() function for output. And it will prints the given statement to the console. And below is the syntax of printf() function is given below:-


Printf statement
The above formatstring can be %d, %c, %s and %f. Here we use %d for integer %c for character %s for string and %f for floats.

scanf() function


We used scanf() function for input in C language. It basically reads the data input from the console.



scanf statement

Program to print square of any number


Here in below example we gets input from user by scanf() function and after that we do square of number is print on console by printf() function



Square Program in C

Output:-


input your number: 10
square of number is: 100


The scanf("%d",&number) statement reads integer number from the console and stores the given value in number variable.

The printf("square of number is:%d ",number*number) statement prints the square of number on the console.

Program to print sum of two number


Here in below example we have intialize 3 integer variable as int and in 2 we take input and 3rd one is store the result then we will print the 3rd variable with printf function



Program of sum in C

Output:-


Input first number: 8
Input second number: 9
Sum of 2 number is: 17





Other Important Questions
Features of C
Introduction to C
History of C Language
Install C Language
C Variables







 
Top Searches:asp net questions vb net questions sql query uddl questions class javascript Questions sharepoint interview questions and concept silverlight questions and concept wcf questions beans general knowledge ajax questions
PHP | Biztalk | Testing | SAP | HR |