Arithmetic Operators Example Program in Dart
This code is also written in the Dart programming language and demonstrates how to perform basic arithmetic operations on two numbers entered by the user. Here's what's happening in this code:
- import 'dart:io'; : This line imports the dart:io library, which provides access to I/O operations in Dart.
- void main(): This line defines the main function for the program.
- var a, b;: This line declares two variables a and b without specifying their data types.
- print('Enter The Value of A & B : ');: This line outputs a message to the console, prompting the user to enter the values of a and b.
- a = int.parse(stdin.readLineSync());: This line reads a line of text from the standard input stream, parses it as an integer using the int.parse() function, and then stores it in the a variable.
- b = int.parse(stdin.readLineSync());: This line reads another line of text from the standard input stream, parses it as an integer using the int.parse() function, and then stores it in the b variable.
- print('Addition : ${a + b}'); : This line outputs the sum of a and b to the console using string interpolation.
- print('Subtraction : ${a - b}');: This line outputs the difference between a and b to the console using string interpolation.
- print('Multiplication : ${a * b}');: This line outputs the product of a and b to the console using string interpolation.
- print('Division : ${a / b}'); : This line outputs the quotient of a and b to the console using string interpolation.
- print('Mod : ${a % b}'); : This line outputs the remainder of a divided by b to the console using string interpolation.
Overall, this program demonstrates how to get input from the user using the standard input stream in Dart, and how to perform basic arithmetic operations on the input values.
Source Code
import 'dart:io';
//a2+b2+2ab
void main(){
var a,b;
print('Enter The Value of A & B : ');
a=int.parse(stdin.readLineSync());
b=int.parse(stdin.readLineSync());
print('Addition : ${a+b}');
print('Subtraction : ${a-b}');
print('Multiplication : ${a*b}');
print('Division : ${a/b}');
print('Mod : ${a%b}');
}
To download raw file
Click Here
Output
Enter The Value of A & B :
20
30
Addition : 50
Subtraction : -10
Multiplication : 600
Division : 0.6666666666666666
Mod : 20