| |
|
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:-
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.
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
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
Output:-
Input first number: 8
Input second number: 9
Sum of 2 number is: 17 | |
|
|
|
|