1. ## modulus

How ye doin. New to this, friend recommended it.

Have to do a matrix 12x12 and the user inputs the first row of what is to go in. Then i have to invert this row and put it in the first column. I have been given the formula to do this but not quite sure how to put it into action. this has to be done with all the columns. i presume i have to put it into a for loop in order for it to work. sorry bout the stupidness if this is easy!!

formula is:
Pm,n = [(P1,n +(Pm,1 - P1,1)]mod12

Code:
```#include<stdio.h>
#include<stdlib.h>

int main()
{

char userinput[12][12];      /* declaration of array to hold the row*/
//char temp[2];
int i;     /* i is te value to go through the array*/
int j;

printf("Please enter the tone row \n Please note only the first inputted character shall be accepted \n");     /*gets the user to enter tone row*/

for(i = 0 ; i < 12; i++){ 	//for loop to input the row into the loop
scanf("%s", &userinput[i]);

}

for (j = 0; j < 12; j++){

for (i = 0; i < 12; i++){

scanf("%s",userinput[j]);

userinput[i][j] = ([i][j] + (([i][j]) - ([i][j])))mod12;
}
}

for(i = 0; i < 12; i++){        //for loop to print out the array after input

printf("%s",userinput[i]);
}

printf("\n");

}```
This is what i have already.

2. In C the modulus operator is % not mod.

IE: 10 % 3 = 1

3. have you any idea why "error: parse error before '[' token" would come up when i try to compile it?

4. The line wants to look something like this:
Code:
`userinput[i][j] = (userinput[i][j] + ((userinput[i][j]) - (userinput[i][j]))&#37;12;`
You cant just say [i][j] and expect the compiler to know that you are referring to the userinput array. Hope that solves your problem.

5. scanf("&#37;s", ...) is not safe. Suggest you read my signature.

6. mike your working wonders for me here.

what your saying is working but somehow i cannot finaliza things.

(a). All the manipulations with the serial forms can be treated by arithmetical formula's. in this case, the formulas for the creation of the first column inverse could be:

Pm,1 = [(Pm-1,1 + (P1,m-1 - P1,m)]mod12

the subsequent transposition of the original series:

Pm,n = [(P1,n + (Pm,1 - P1,1)]mod12.

so i think that i start on 1 and put in the first formula for the first column, and then create another for loop to loop through the rest of the matrix then??

Here's what i have now:

Code:
```#include<stdio.h>
#include<stdlib.h>

int main()
{

int userinput[12][12];      /* declaration of array to hold the row*/
//char temp[2];
int i;     /* i is te value to go through the array*/
int j;

printf("Please enter the tone row \n Please note only the first inputted character shall be accepted \n");     /*gets the user to enter tone row*/

for(j = 0 ; j < 12; j++){ 	//for loop to input the row into the loop
scanf("%d", &userinput[j]);

}

for(j = 0; j < 12; j++){        //for loop to print out the array after input

printf("%d",userinput[j]);

}
printf("\n");

for (i = 1; i < 11; i++){

for (j = 1; j < 11; j++){

//scanf("%d",userinput[i][j]);

userinput[i][j] = (userinput[i][j] + ((userinput[i][j]) - (userinput[i][j+1])))%12;
printf("%d", userinput[i]);
}
}
}```

7. cheers Elysia, will try keep away! seems to be runnin better now!

Maybe you might be able to help me with this problem i have here

8. Well, first you could work a little on indentation. Every block ({ and }) should be indented with (at least) 2 spaces, preferably a tab. You're not specifying that row/column you read into either. Since the array is 2D, you would want to specify [row][column] when reading into your array, while you're just reading into array[row].
For the first row, it might be array[0][column].

Popular pages Recent additions