Hello,

I'm working my way through a book on arithmetic.  There is a table of
the numbers from 1 to 99:

1       8       15      22      29      36      43      50
57      64      71      78      85      92      99      6
13      20      27      34      41      48      55      62
69      76      83      90      97      4       11      18
25      32      39      46      53      60      67      74
81      88      95      2       9       16      23      30
37      44      51      58      65      72      79      86
93      7       14      21      28      35      42      49
56      63      70      77      84      91      98      5
12      19      26      33      40      47      54      61
68      75      82      89      96      3       10      17
24      31      38      45      52      59      66      73
80      87      94

the instructions are to work down the columns, not across the
page, answers are given for each exercise.  The idea is to practise
addition or multiplication.  I wanted to be able to have the solutions
in the form of the original table rather than sequentially.  I also
found one error in the answers, so wanted something more reliable.  I
have

table1.h:

const int table1[99] = {1,57,13,69,25,81,37,93,56,12,68,24,80,
        8,64,20,76,32,88,44,7,63,19,75,31,87,
        15,71,27,83,39,95,51,14,70,26,82,38,94,
        22,78,34,90,46,2,58,21,77,33,89,45,
        29,85,41,97,53,9,65,28,84,40,96,52,
        36,92,48,4,60,16,72,35,91,47,3,59,
        43,99,55,11,67,23,79,42,98,54,10,66,
        50,6,62,18,74,30,86,49,5,61,17,73};

add.c:

#include "table1.h"
#include <stdio.h>
int main(void)
{
        int a=17;
        int i;
        int j;
        for (j=0;j<2;j++)
        {
        for (i=0+j;i<42;i=i+13)
                printf("%d\t",table1[i]+a);
        for (i=51+j;i<99;i=i+12)
                printf("%d\t",table1[i]+a);
        printf("\n");
        }
        for (j=2;j<12;j++)
        {
        for (i=0+j;i<42+j;i=i+13)
                printf("%d\t",table1[i]+a);
        for (i=51+j;i<99;i=i+12)
                printf("%d\t",table1[i]+a);
        printf("\n");
        }
        printf("%d\t%d\t%d\n",table1[12]+a,table1[25]+a,table1[38]+a);
        return 0;
}

multiply.c is the same as add.c, except the operation is different.

was there a less torturous way of doing this (ignoring the obvious flaw
of having to recompile for every new question)?

Rick

Reply via email to