Arithmetic/Integer: Difference between revisions
Content added Content deleted
(New task, added C++ and Pascal) |
|||
Line 2: | Line 2: | ||
{{basic data operation}} |
{{basic data operation}} |
||
Get two integers from the user, and then output the sum, difference, product, integer quotient and remainder of those numbers. Don't include error handling. |
Get two integers from the user, and then output the sum, difference, product, integer quotient and remainder of those numbers. Don't include error handling. |
||
==[[Ada]]== |
|||
[[Category:Ada]] |
|||
with Ada.Text_Io; |
|||
with Ada.Integer_Text_IO; |
|||
procedure Integer_Arithmetic is |
|||
use Ada.Text_IO; |
|||
use Ada.Integer_Text_Io; |
|||
A, B : Integer; |
|||
begin |
|||
Get(A); |
|||
Get(B); |
|||
Put_Line("a+b = " & Integer'Image(A + B)); |
|||
Put_Line("a-b = " & Integer'Image(A - B)); |
|||
Put_Line("a*b = " & Integer'Image(A * B)); |
|||
Put_Line("a/b = " & Integer'Image(A / B) & ", remainder " & Integer'Image(A mod B)); |
|||
end Integer_Arithmetic; |
|||
==[[C plus plus|C++]]== |
==[[C plus plus|C++]]== |
Revision as of 17:45, 28 May 2007
![Task](http://static.miraheze.org/rosettacodewiki/thumb/b/ba/Rcode-button-task-crushed.png/64px-Rcode-button-task-crushed.png)
You are encouraged to solve this task according to the task description, using any language you may know.
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |
Comparison |
Matching
Memory Operations
Pointers & references |
Addresses
Get two integers from the user, and then output the sum, difference, product, integer quotient and remainder of those numbers. Don't include error handling.
Ada
with Ada.Text_Io; with Ada.Integer_Text_IO; procedure Integer_Arithmetic is use Ada.Text_IO; use Ada.Integer_Text_Io; A, B : Integer; begin Get(A); Get(B); Put_Line("a+b = " & Integer'Image(A + B)); Put_Line("a-b = " & Integer'Image(A - B)); Put_Line("a*b = " & Integer'Image(A * B)); Put_Line("a/b = " & Integer'Image(A / B) & ", remainder " & Integer'Image(A mod B)); end Integer_Arithmetic;
C++
#include <iostream> int main() { int a, b; std::cin >> a >> b; std::cout << "a+b = " << a+b << "\n"; std::cout << "a-b = " << a-b << "\n"; std::cout << "a*b = " << a*b << "\n"; std::cout << "a/b = " << a/b << ", remainder " << a%b << "\n"; }
Pascal
program arithmetic(input, output) var a, b: integer; begin readln(a, b); writeln('a+b = ', a+b); writeln('a-b = ', a-b); writeln('a*b = ', a*b); writeln('a/b = ', a div b, ', remainder ", a mod b); end.