Definition:
The scanf() function in C is used to accept input from the user through the keyboard. It allows users to enter values during program execution instead of using fixed values.
Explanation:
This program accepts two numbers from the user using the scanf() function. It then performs addition, subtraction, multiplication, and division on the entered numbers and displays the results using the printf() function.
Explanation: This program accepts two numbers from the user using the scanf() function and displays their sum.
#include <stdio.h> #include <conio.h> main() { int a,b,sum; clrscr(); printf("Enter First Number : "); scanf("%d",&a); printf("Enter Second Number : "); scanf("%d",&b); sum = a + b; printf("\nAddition = %d",sum); getch(); }
Output:
Explanation: This program accepts two numbers from the user using the scanf() function and displays their product.
#include <stdio.h> #include <conio.h> main() { int a,b,multi; clrscr(); printf("Enter First Number : "); scanf("%d",&a); printf("Enter Second Number : "); scanf("%d",&b); multi = a * b; printf("\nMultiplication = %d",multi); getch(); }
Output:
Explanation: This program accepts two numbers from the user and performs addition, subtraction, multiplication, and division.
#include <stdio.h> #include <conio.h> main() { int a,b,add,sub,multi,div; clrscr(); printf("Enter The Value Of A : "); scanf("%d",&a); printf("Enter The Value Of B : "); scanf("%d",&b); add = a + b; sub = a - b; multi = a * b; div = a / b; printf("\nAddition = %d",add); printf("\nSubtraction = %d",sub); printf("\nMultiplication = %d",multi); printf("\nDivision = %d",div); getch(); }
Output:
scanf() for user input and printf() for output.+ operator.#include <stdio.h> main() { int a,b; scanf("%d%d",&a,&b); printf("Addition = %d",a+b); getch(); }
- operator.#include <stdio.h> #include <conio.h> main() { int a,b; scanf("%d%d",&a,&b); printf("Subtraction = %d",a-b); getch(); }
scanf() function.* operator after accepting two numbers.#include <stdio.h> #include <conio.h> main() { int a,b; scanf("%d%d",&a,&b); printf("Multiplication = %d",a*b); getch(); }