Home » Archimedes archive » Acorn User » AU 1994-11.adf » !C_C » c/Arithmetic
c/Arithmetic
This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.
Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.
Tape/disk: | Home » Archimedes archive » Acorn User » AU 1994-11.adf » !C_C |
Filename: | c/Arithmetic |
Read OK: | ✔ |
File size: | 034A bytes |
Load address: | 0000 |
Exec address: | 0000 |
File contents
/* Arithmetic, which adds, subtracts and generally messes around with */ /* some variables */ /* by David Matthewman */ #include <stdio.h> main() { int x=977, y=311; printf("x is %d\ny is %d\n\n", x, y); printf("x plus y = %d\n", x + y ); printf("x minus y = %d\n", x - y); printf("x times y = %d\n", x * y); printf("x divided by y (integer division) = %d\n", x / y); printf("x divided by y (real no. division) = %6.4f\n", (double)x / y); printf("x divided by y (remainder) = %d\n", x % y); printf("x OR y = %d\n", x | y); printf("x EOR y = %d\n", x ^ y); printf("x AND y = %d\n", x & y); printf("x left shifted by 2 = %d\n", x << 2); printf("x right shifted by 2 = %d\n", x >> 2); return 0; }
00000000 2f 2a 20 41 72 69 74 68 6d 65 74 69 63 2c 20 77 |/* Arithmetic, w| 00000010 68 69 63 68 20 61 64 64 73 2c 20 73 75 62 74 72 |hich adds, subtr| 00000020 61 63 74 73 20 61 6e 64 20 67 65 6e 65 72 61 6c |acts and general| 00000030 6c 79 20 6d 65 73 73 65 73 20 61 72 6f 75 6e 64 |ly messes around| 00000040 20 77 69 74 68 20 2a 2f 0a 2f 2a 20 73 6f 6d 65 | with */./* some| 00000050 20 76 61 72 69 61 62 6c 65 73 20 20 20 20 20 20 | variables | 00000060 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | * 00000080 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2a | *| 00000090 2f 0a 2f 2a 20 62 79 20 44 61 76 69 64 20 4d 61 |/./* by David Ma| 000000a0 74 74 68 65 77 6d 61 6e 20 20 20 20 20 20 20 20 |tthewman | 000000b0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | * 000000d0 20 20 20 20 20 20 20 20 2a 2f 0a 0a 23 69 6e 63 | */..#inc| 000000e0 6c 75 64 65 20 3c 73 74 64 69 6f 2e 68 3e 0a 0a |lude <stdio.h>..| 000000f0 6d 61 69 6e 28 29 0a 7b 0a 20 20 69 6e 74 20 78 |main().{. int x| 00000100 3d 39 37 37 2c 20 79 3d 33 31 31 3b 0a 0a 20 20 |=977, y=311;.. | 00000110 70 72 69 6e 74 66 28 22 78 20 69 73 20 25 64 5c |printf("x is %d\| 00000120 6e 79 20 69 73 20 25 64 5c 6e 5c 6e 22 2c 20 78 |ny is %d\n\n", x| 00000130 2c 20 79 29 3b 0a 20 20 70 72 69 6e 74 66 28 22 |, y);. printf("| 00000140 78 20 70 6c 75 73 20 79 20 20 3d 20 25 64 5c 6e |x plus y = %d\n| 00000150 22 2c 20 78 20 2b 20 79 20 29 3b 0a 20 20 70 72 |", x + y );. pr| 00000160 69 6e 74 66 28 22 78 20 6d 69 6e 75 73 20 79 20 |intf("x minus y | 00000170 3d 20 25 64 5c 6e 22 2c 20 78 20 2d 20 79 29 3b |= %d\n", x - y);| 00000180 0a 20 20 70 72 69 6e 74 66 28 22 78 20 74 69 6d |. printf("x tim| 00000190 65 73 20 79 20 3d 20 25 64 5c 6e 22 2c 20 78 20 |es y = %d\n", x | 000001a0 2a 20 79 29 3b 0a 20 20 70 72 69 6e 74 66 28 22 |* y);. printf("| 000001b0 78 20 64 69 76 69 64 65 64 20 62 79 20 79 20 28 |x divided by y (| 000001c0 69 6e 74 65 67 65 72 20 64 69 76 69 73 69 6f 6e |integer division| 000001d0 29 20 20 3d 20 25 64 5c 6e 22 2c 20 20 20 20 78 |) = %d\n", x| 000001e0 20 2f 20 79 29 3b 0a 20 20 70 72 69 6e 74 66 28 | / y);. printf(| 000001f0 22 78 20 64 69 76 69 64 65 64 20 62 79 20 79 20 |"x divided by y | 00000200 28 72 65 61 6c 20 6e 6f 2e 20 64 69 76 69 73 69 |(real no. divisi| 00000210 6f 6e 29 20 3d 20 25 36 2e 34 66 5c 6e 22 2c 20 |on) = %6.4f\n", | 00000220 28 64 6f 75 62 6c 65 29 78 20 2f 20 79 29 3b 0a |(double)x / y);.| 00000230 20 20 70 72 69 6e 74 66 28 22 78 20 64 69 76 69 | printf("x divi| 00000240 64 65 64 20 62 79 20 79 20 28 72 65 6d 61 69 6e |ded by y (remain| 00000250 64 65 72 29 20 20 20 20 20 20 20 20 20 3d 20 25 |der) = %| 00000260 64 5c 6e 22 2c 20 20 20 20 78 20 25 20 79 29 3b |d\n", x % y);| 00000270 0a 20 20 70 72 69 6e 74 66 28 22 78 20 4f 52 20 |. printf("x OR | 00000280 79 20 20 3d 20 25 64 5c 6e 22 2c 20 78 20 7c 20 |y = %d\n", x | | 00000290 79 29 3b 0a 20 20 70 72 69 6e 74 66 28 22 78 20 |y);. printf("x | 000002a0 45 4f 52 20 79 20 3d 20 25 64 5c 6e 22 2c 20 78 |EOR y = %d\n", x| 000002b0 20 5e 20 79 29 3b 0a 20 20 70 72 69 6e 74 66 28 | ^ y);. printf(| 000002c0 22 78 20 41 4e 44 20 79 20 3d 20 25 64 5c 6e 22 |"x AND y = %d\n"| 000002d0 2c 20 78 20 26 20 79 29 3b 0a 20 20 70 72 69 6e |, x & y);. prin| 000002e0 74 66 28 22 78 20 6c 65 66 74 20 73 68 69 66 74 |tf("x left shift| 000002f0 65 64 20 62 79 20 32 20 20 3d 20 25 64 5c 6e 22 |ed by 2 = %d\n"| 00000300 2c 20 78 20 3c 3c 20 32 29 3b 0a 20 20 70 72 69 |, x << 2);. pri| 00000310 6e 74 66 28 22 78 20 72 69 67 68 74 20 73 68 69 |ntf("x right shi| 00000320 66 74 65 64 20 62 79 20 32 20 3d 20 25 64 5c 6e |fted by 2 = %d\n| 00000330 22 2c 20 78 20 3e 3e 20 32 29 3b 0a 0a 20 20 72 |", x >> 2);.. r| 00000340 65 74 75 72 6e 20 30 3b 0a 7d |eturn 0;.}| 0000034a