InterviewSolution
Saved Bookmarks
| 1. |
printf() and scanf() |
|
Answer» printf() and scanf() printf() functionWe 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() functionWe used scanf() function for input in C language. It basically reads the DATA input from the console. ![]() Program to print square of any NUMBERHere 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 numberHere 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 |
|