1.

printf() and scanf()

Answer»

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


Discussion

No Comment Found