Arithmetic/Integer: Difference between revisions
Content added Content deleted
(→[[Perl]]: new example without map and the array -- that was distracting from the intent of the task) |
(add C example) |
||
Line 21: | Line 21: | ||
Put_Line("a/b = " & Integer'Image(A / B) & ", remainder " & Integer'Image(A mod B)); |
Put_Line("a/b = " & Integer'Image(A / B) & ", remainder " & Integer'Image(A mod B)); |
||
end Integer_Arithmetic; |
end Integer_Arithmetic; |
||
==[[C]]== |
|||
[[Category:C]] |
|||
#include <stdio.h> |
|||
#include <stdlib.h> |
|||
int main(int argc, char *argv[]) |
|||
{ |
|||
int a, b; |
|||
if (argc < 3) exit(1); |
|||
b = atoi(argv[--argc]); |
|||
if (b == 0) exit(2); |
|||
a = atoi(argv[--argc]); |
|||
printf("a+b = %d\n", a+b); |
|||
printf("a-b = %d\n", a-b); |
|||
printf("a*b = %d\n", a*b); |
|||
printf("a/b = %d\n", a/b); |
|||
printf("a%%b = %d\n", a%b); |
|||
return 0; |
|||
} |
|||
==[[C plus plus|C++]]== |
==[[C plus plus|C++]]== |
||
Line 34: | Line 54: | ||
std::cout << "a*b = " << a*b << "\n"; |
std::cout << "a*b = " << a*b << "\n"; |
||
std::cout << "a/b = " << a/b << ", remainder " << a%b << "\n"; |
std::cout << "a/b = " << a/b << ", remainder " << a%b << "\n"; |
||
return 0; |
|||
} |
} |
||