Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

/prog/ Challenge

Name: Anonymous 2008-05-18 14:34

Make a program in the programming language of your choice that prints a multiplication table based on user input.  I this is not homework as I already made a program that runs.

Example output:

C:\Documents and Settings\xxxxxx\Desktop>multi.py
Enter the starting value:1
Enter the ending value:20
  1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20
  2   4   6   8  10  12  14  16  18  20  22  24  26  28  30  32  34  36  38  40
  3   6   9  12  15  18  21  24  27  30  33  36  39  42  45  48  51  54  57  60
  4   8  12  16  20  24  28  32  36  40  44  48  52  56  60  64  68  72  76  80
  5  10  15  20  25  30  35  40  45  50  55  60  65  70  75  80  85  90  95 100
  6  12  18  24  30  36  42  48  54  60  66  72  78  84  90  96 102 108 114 120
  7  14  21  28  35  42  49  56  63  70  77  84  91  98 105 112 119 126 133 140
  8  16  24  32  40  48  56  64  72  80  88  96 104 112 120 128 136 144 152 160
  9  18  27  36  45  54  63  72  81  90  99 108 117 126 135 144 153 162 171 180
 10  20  30  40  50  60  70  80  90 100 110 120 130 140 150 160 170 180 190 200
 11  22  33  44  55  66  77  88  99 110 121 132 143 154 165 176 187 198 209 220
 12  24  36  48  60  72  84  96 108 120 132 144 156 168 180 192 204 216 228 240
 13  26  39  52  65  78  91 104 117 130 143 156 169 182 195 208 221 234 247 260
 14  28  42  56  70  84  98 112 126 140 154 168 182 196 210 224 238 252 266 280
 15  30  45  60  75  90 105 120 135 150 165 180 195 210 225 240 255 270 285 300
 16  32  48  64  80  96 112 128 144 160 176 192 208 224 240 256 272 288 304 320
 17  34  51  68  85 102 119 136 153 170 187 204 221 238 255 272 289 306 323 340
 18  36  54  72  90 108 126 144 162 180 198 216 234 252 270 288 306 324 342 360
 19  38  57  76  95 114 133 152 171 190 209 228 247 266 285 304 323 342 361 380
 20  40  60  80 100 120 140 160 180 200 220 240 260 280 300 320 340 360 380 400

Name: Anonymous 2008-05-18 14:36

C:\Documents and Settings\xxxxxx\Desktop>multi.py
Do you really expect us to do something?

Name: Anonymous 2008-05-18 14:56


#!/bin/sh
cat /dev/random | perl

Name: Anonymous 2008-05-18 15:10

>>3
Good GOD, man! You just authored a web browser.

Name: Anonymous 2008-05-18 15:15

>>2
Yes Christopher.  Do you?

Name: Anonymous 2008-05-18 15:17

>>3
uuoc

perl < /dev/random

Name: Anonymous 2008-05-18 15:33

d:\>perl -e "print join qq{\n},map{$a=$_;join q{ },map{sprintf q{%-3d},$a*$_}1..20}1..20"
1   2   3   4   5   6   7   8   9   10  11  12  13  14  15  16  17  18  19  20
2   4   6   8   10  12  14  16  18  20  22  24  26  28  30  32  34  36  38  40
3   6   9   12  15  18  21  24  27  30  33  36  39  42  45  48  51  54  57  60
4   8   12  16  20  24  28  32  36  40  44  48  52  56  60  64  68  72  76  80
5   10  15  20  25  30  35  40  45  50  55  60  65  70  75  80  85  90  95  100
6   12  18  24  30  36  42  48  54  60  66  72  78  84  90  96  102 108 114 120
7   14  21  28  35  42  49  56  63  70  77  84  91  98  105 112 119 126 133 140
8   16  24  32  40  48  56  64  72  80  88  96  104 112 120 128 136 144 152 160
9   18  27  36  45  54  63  72  81  90  99  108 117 126 135 144 153 162 171 180
10  20  30  40  50  60  70  80  90  100 110 120 130 140 150 160 170 180 190 200
11  22  33  44  55  66  77  88  99  110 121 132 143 154 165 176 187 198 209 220
12  24  36  48  60  72  84  96  108 120 132 144 156 168 180 192 204 216 228 240
13  26  39  52  65  78  91  104 117 130 143 156 169 182 195 208 221 234 247 260
14  28  42  56  70  84  98  112 126 140 154 168 182 196 210 224 238 252 266 280
15  30  45  60  75  90  105 120 135 150 165 180 195 210 225 240 255 270 285 300
16  32  48  64  80  96  112 128 144 160 176 192 208 224 240 256 272 288 304 320
17  34  51  68  85  102 119 136 153 170 187 204 221 238 255 272 289 306 323 340
18  36  54  72  90  108 126 144 162 180 198 216 234 252 270 288 306 324 342 360
19  38  57  76  95  114 133 152 171 190 209 228 247 266 285 304 323 342 361 380
20  40  60  80  100 120 140 160 180 200 220 240 260 280 300 320 340 360 380 400

Name: Anonymous 2008-05-18 16:14

>>7
Do you really think you are smart by copying the output of /dev/random and posting it here as if you had written it yourself?

Name: Anonymous 2008-05-18 16:14

>>7
You're a nut! You're crazy in the coconut !

Name: Anonymous 2008-05-18 16:21


import System
import Monad
import List

mulTable a b = map (ap (map (*) [a..b]) . return) [a..b]

main =
   do [a, b] <- mapM readIO =<< getArgs
      let offShow x = show x ++ replicate (offset x) ' '
          offset x = log10 (maximum $ last table) - log10 x
          log10 = floor . logBase 10 . fromIntegral
          table = mulTable a b
      putStr $ unlines $ map (unwords . map offShow) table

Name: Anonymous 2008-05-18 16:23

module Main where

import Data.List
import Text.Printf

printTable a b = mapM_ (putStrLn . intercalate " " . map (printf $ "%" ++ show (length . show $ b^2) ++ "d")) $ table [a..b]
table xs = map ((`map` xs) . (*)) xs

Name: 11 2008-05-18 16:37

>>10 reminded me that unwords exists. Revised version:

module Main where

import Text.Printf

printTable a b = mapM_ (putStrLn . unwords . map (printf $ "%" ++ show (length . show $ b^2) ++ "d")) $ table [a..b]
table xs = map ((`map` xs) . (*)) xs

Name: >>10 2008-05-18 16:43

>>11,12
That was inspiring, good sir. Thank you for sharing.

Name: Anonymous 2008-05-18 17:06

[code]module Main where

import Text.Printf

printTable a b = mapM_ (putStrLn . unwords . map (printf "%*d" (length . show $ b^2))) $ table [a..b]
table xs = map ((`map` xs) . (*)) xs
[code]

Name: Anonymous 2008-05-18 17:08

BBCode failure
module Main where

import Text.Printf

printTable a b = mapM_ (putStrLn . unwords . map (printf "%*d" (length . show $ b^2))) $ table [a..b]
table xs = map ((`map` xs) . (*)) xs

Name: Anonymous 2008-05-18 17:11

I want you to stop using infixified functions.

Name: Anonymous 2008-05-18 17:18

<3 \t
anon@Emilie ~ % php -r 'foreach (range(1,20) as $x){ foreach (range(1,20) as $y) echo $x*$y . "\t"; echo "\n";}'                                            0
1    2    3    4    5    6    7    8    9    10    11    12    13    14    15    16    17    18    19    20   
2    4    6    8    10    12    14    16    18    20    22    24    26    28    30    32    34    36    38    40   
3    6    9    12    15    18    21    24    27    30    33    36    39    42    45    48    51    54    57    60   
4    8    12    16    20    24    28    32    36    40    44    48    52    56    60    64    68    72    76    80   
5    10    15    20    25    30    35    40    45    50    55    60    65    70    75    80    85    90    95    100   
6    12    18    24    30    36    42    48    54    60    66    72    78    84    90    96    102    108    114    120   
7    14    21    28    35    42    49    56    63    70    77    84    91    98    105    112    119    126    133    140   
8    16    24    32    40    48    56    64    72    80    88    96    104    112    120    128    136    144    152    160   
9    18    27    36    45    54    63    72    81    90    99    108    117    126    135    144    153    162    171    180   
10    20    30    40    50    60    70    80    90    100    110    120    130    140    150    160    170    180    190    200   
11    22    33    44    55    66    77    88    99    110    121    132    143    154    165    176    187    198    209    220   
12    24    36    48    60    72    84    96    108    120    132    144    156    168    180    192    204    216    228    240   
13    26    39    52    65    78    91    104    117    130    143    156    169    182    195    208    221    234    247    260   
14    28    42    56    70    84    98    112    126    140    154    168    182    196    210    224    238    252    266    280   
15    30    45    60    75    90    105    120    135    150    165    180    195    210    225    240    255    270    285    300   
16    32    48    64    80    96    112    128    144    160    176    192    208    224    240    256    272    288    304    320   
17    34    51    68    85    102    119    136    153    170    187    204    221    238    255    272    289    306    323    340   
18    36    54    72    90    108    126    144    162    180    198    216    234    252    270    288    306    324    342    360   
19    38    57    76    95    114    133    152    171    190    209    228    247    266    285    304    323    342    361    380   
20    40    60    80    100    120    140    160    180    200    220    240    260    280    300    320    340    360    380    400

Name: Anonymous 2008-05-18 18:10

>>17
Stop using capital letters in your hostname.

Name: Anonymous 2008-05-18 18:16

>>17
Stop using PHP.

Name: Anonymous 2008-05-18 18:18

Shitty threads like this always make me want to learn perl.

Name: Anonymous 2008-05-18 18:19

>>20
Resist, it's not worth it.

Name: Anonymous 2008-05-18 18:50

>>17
Emilie
Tits or GTFO

Name: Anonymous 2008-05-18 19:31

>>22
We named the machine Emilie.

Name: Anonymous 2008-05-18 19:39

module Main where{import Text.Printf;printTable a b=(putStrLn.unwords.map(printf"%*d"$length.show$b^2))`mapM_`(\xs->map((`map`xs).(*))xs)[a..b]}

Name: Anonymous 2008-05-18 20:18

>>23
Named after my second girlfriend when I was 4.

Name: Anonymous 2008-05-18 21:42

>>23
Name after my penis.

Name: Anonymous 2008-05-18 21:49

>>26
*Named

Name: Anonymous 2008-05-18 22:02

>>17
I came in you.

Name: Anonymous 2008-05-18 22:16

>>19
Ok.

module Main where
import Text.Printf

table :: [[Int]]
table = [[x*y | y <- [1..]] | x <- [1..]]

main :: IO ()
main = putStrLn . unlines . map unwords $ map (map $ printf "%3d") $ take 20 $ map (take 20) table

Name: Anonymous 2008-05-18 23:04


import prog
while True:
    newthread('lol','lol','lol','lol')

THIS IS WHY WE CAN'T HAVE NICE THINGS

Name: Anonymous 2008-05-19 1:35

Name: Anonymous 2008-05-19 1:53

Fuck you.



#include <iostream>
using namespace std;

int main()
{
  int start, end;
  cout << "Enter the starting value: ";
  cin >> start;
  cout << "Enter the ending value: ";
  cin >> end;
  for(int i = start; i < (end + 1); i++)
  {
      cout << "\n";
      for(int j = start; j < (end + 1); j++)
      {
          cout << (j * i) << " ";
      }
  }
  cin.ignore();
  cin.get();
  return 0;
}

Name: Anonymous 2008-05-19 1:56

Hmm. Ignore the previous post.
It achieves the same outcome as the OP, but it's not properly creating a multiplication table.

Name: Anonymous 2008-05-19 1:57

hax(*(>>31).anus);

Name: Anonymous 2008-05-19 3:40

xxxxxx@olorin$ cat mult.c                                                 < ~ >
#include <inttypes.h>
#include <limits.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>

int main(){
 int len;
 intmax_t start, end;
 fputs("Enter the starting value:", stdout);
 start = strtoimax(fgetln(stdin, &len), NULL, 0);
 fputs("Enter the ending value:", stdout);
 end = strtoimax(fgetln(stdin, &len), NULL, 0);
 for(intmax_t i = start; i <= end; ++i){
  for(intmax_t j = start; j <= end; ++j)
   printf(" %3" PRIdMAX, i * j);
  puts("");
 }
 return 0;
}
xxxxxx@olorin$ gcc -std=c99 -o mult mult.c                                < ~ >
xxxxxx@olorin$ ./mult                                                     < ~ >
Enter the starting value:1
Enter the ending value:20
   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20
   2   4   6   8  10  12  14  16  18  20  22  24  26  28  30  32  34  36  38  40
   3   6   9  12  15  18  21  24  27  30  33  36  39  42  45  48  51  54  57  60
   4   8  12  16  20  24  28  32  36  40  44  48  52  56  60  64  68  72  76  80
   5  10  15  20  25  30  35  40  45  50  55  60  65  70  75  80  85  90  95 100
   6  12  18  24  30  36  42  48  54  60  66  72  78  84  90  96 102 108 114 120
   7  14  21  28  35  42  49  56  63  70  77  84  91  98 105 112 119 126 133 140
   8  16  24  32  40  48  56  64  72  80  88  96 104 112 120 128 136 144 152 160
   9  18  27  36  45  54  63  72  81  90  99 108 117 126 135 144 153 162 171 180
  10  20  30  40  50  60  70  80  90 100 110 120 130 140 150 160 170 180 190 200
  11  22  33  44  55  66  77  88  99 110 121 132 143 154 165 176 187 198 209 220
  12  24  36  48  60  72  84  96 108 120 132 144 156 168 180 192 204 216 228 240
  13  26  39  52  65  78  91 104 117 130 143 156 169 182 195 208 221 234 247 260
  14  28  42  56  70  84  98 112 126 140 154 168 182 196 210 224 238 252 266 280
  15  30  45  60  75  90 105 120 135 150 165 180 195 210 225 240 255 270 285 300
  16  32  48  64  80  96 112 128 144 160 176 192 208 224 240 256 272 288 304 320
  17  34  51  68  85 102 119 136 153 170 187 204 221 238 255 272 289 306 323 340
  18  36  54  72  90 108 126 144 162 180 198 216 234 252 270 288 306 324 342 360
  19  38  57  76  95 114 133 152 171 190 209 228 247 266 285 304 323 342 361 380
  20  40  60  80 100 120 140 160 180 200 220 240 260 280 300 320 340 360 380 400
xxxxxx@olorin$ rm mult.c mult && fortune                                  < ~ >
O imitators, you slavish herd!
                -- Quintus Horatius Flaccus (Horace)

Name: Anonymous 2008-05-19 4:11

public class MultiplicationTable
{
public static void main(String[] args)
{
System.out.println("Enter the starting value:1");
System.out.println("Enter the ending value:20");
System.out.println("  1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20");
System.out.println("  2   4   6   8  10  12  14  16  18  20  22  24  26  28  30  32  34  36  38  40");
System.out.println("  3   6   9  12  15  18  21  24  27  30  33  36  39  42  45  48  51  54  57  60");
System.out.println("  4   8  12  16  20  24  28  32  36  40  44  48  52  56  60  64  68  72  76  80");
System.out.println("  5  10  15  20  25  30  35  40  45  50  55  60  65  70  75  80  85  90  95 100");
System.out.println("  6  12  18  24  30  36  42  48  54  60  66  72  78  84  90  96 102 108 114 120");
System.out.println("  7  14  21  28  35  42  49  56  63  70  77  84  91  98 105 112 119 126 133 140");
System.out.println("  8  16  24  32  40  48  56  64  72  80  88  96 104 112 120 128 136 144 152 160");
System.out.println("  9  18  27  36  45  54  63  72  81  90  99 108 117 126 135 144 153 162 171 180");
System.out.println(" 10  20  30  40  50  60  70  80  90 100 110 120 130 140 150 160 170 180 190 200");
System.out.println(" 11  22  33  44  55  66  77  88  99 110 121 132 143 154 165 176 187 198 209 220");
System.out.println(" 12  24  36  48  60  72  84  96 108 120 132 144 156 168 180 192 204 216 228 240");
System.out.println(" 13  26  39  52  65  78  91 104 117 130 143 156 169 182 195 208 221 234 247 260");
System.out.println(" 14  28  42  56  70  84  98 112 126 140 154 168 182 196 210 224 238 252 266 280");
System.out.println(" 15  30  45  60  75  90 105 120 135 150 165 180 195 210 225 240 255 270 285 300");
System.out.println(" 16  32  48  64  80  96 112 128 144 160 176 192 208 224 240 256 272 288 304 320");
System.out.println(" 17  34  51  68  85 102 119 136 153 170 187 204 221 238 255 272 289 306 323 340");
System.out.println(" 18  36  54  72  90 108 126 144 162 180 198 216 234 252 270 288 306 324 342 360");
System.out.println(" 19  38  57  76  95 114 133 152 171 190 209 228 247 266 285 304 323 342 361 380");
System.out.println(" 20  40  60  80 100 120 140 160 180 200 220 240 260 280 300 320 340 360 380 400");
}
}

Name: Anonymous 2008-05-19 5:12

>>36
I lol'd, even though this was so predictable and repetitive.

Name: Anonymous 2008-05-19 5:38

>>36
EXPERT LOOP UNROLLING

Name: Anonymous 2008-05-19 7:19

>>38
Don't you mean ENTERPRISE?

Name: Anonymous 2008-05-19 11:08

>>38
[b][u]EXPERT LOOP UNROLLER[/u][/b]
[b][u]ENTERPRISE LOOP UNROLLING[/u][/b]

lrn2adjective.

Name: Anonymous 2008-05-19 11:08

>>40
lrn2bbcode

Name: Anonymous 2008-05-19 12:20

>>40
>>41
lrn2beDifferentFags

Name: Anonymous 2008-05-19 13:06

>>42
lrn2notCare

Name: Anonymous 2008-05-19 14:07

stop using camel case, dammit

Name: Anonymous 2008-05-19 14:43

>>44
sorry.
i   f e e l   k i n d   o f   b a d   a b o u t   i t   : (

Name: Anonymous 2008-05-19 19:35

your doing it wrong.

Name: Anonymous 2008-05-19 20:36

your doingness is wrong

Name: Anonymous 2008-05-19 20:52

>>46
I know.
i   f e e l   k i n d   o f   b a d   a b o u t   i t   : (

Name: Sgt.Kabukiman氵 2012-05-23 5:51

All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy

Don't change these.
Name: Email:
Entire Thread Thread List