Find the index of the column and the row that contains the same number sequence
I want to find the index of the column and the row that contains the same number sequence in a 2D array.
for example
{2, 3, 2, 6}
{3, 6, 3, 10}
{7, 4, 2, 12}
{6, 8, 6, 4}
in this example, the program must return the line index 0 and the column index 2
I wrote a program using C language but it doesn't work
# include <stdio.h>
int main(){
char tab[3][3];
int simiLgn, simiClm;
for (int i = 0; i<3; i++){
for (int j = 0; j<3; j++){
printf("Tableau[%d][%d]=", i, j);
scanf("%d", &tab[i][j]);
}
}
for (int i = 0; i<3; i++){
for (int j = 0; j<3; j++){
printf("%d t", tab[i][j]);
}
printf("n");
}
int fix_lgn = 0;
int fix_col = 0;
while (fix_lgn<3){
while (fix_col<3){
for (int i=0, j=0; i<3, j<3 ; i++, j++){
if(tab[fix_lgn][j] == tab[i][fix_col]){
simiLgn = fix_lgn;
simiClm = fix_col;
}
else{
simiLgn = -1;
simiClm = -1;
}
}
fix_col++;
}
fix_col = 0;
fix_lgn++;
}
printf("ligne index: %dn", simiLgn);
printf("colonne index: %dn", simiClm);
return 0;
}
Thank you
c arrays
add a comment |
I want to find the index of the column and the row that contains the same number sequence in a 2D array.
for example
{2, 3, 2, 6}
{3, 6, 3, 10}
{7, 4, 2, 12}
{6, 8, 6, 4}
in this example, the program must return the line index 0 and the column index 2
I wrote a program using C language but it doesn't work
# include <stdio.h>
int main(){
char tab[3][3];
int simiLgn, simiClm;
for (int i = 0; i<3; i++){
for (int j = 0; j<3; j++){
printf("Tableau[%d][%d]=", i, j);
scanf("%d", &tab[i][j]);
}
}
for (int i = 0; i<3; i++){
for (int j = 0; j<3; j++){
printf("%d t", tab[i][j]);
}
printf("n");
}
int fix_lgn = 0;
int fix_col = 0;
while (fix_lgn<3){
while (fix_col<3){
for (int i=0, j=0; i<3, j<3 ; i++, j++){
if(tab[fix_lgn][j] == tab[i][fix_col]){
simiLgn = fix_lgn;
simiClm = fix_col;
}
else{
simiLgn = -1;
simiClm = -1;
}
}
fix_col++;
}
fix_col = 0;
fix_lgn++;
}
printf("ligne index: %dn", simiLgn);
printf("colonne index: %dn", simiClm);
return 0;
}
Thank you
c arrays
1
i<3, j<3this doesn't do what you think, switch toi<3 && j<3, and here:tab[fix_lgn, j]you wanttab[fix_lgn][j]
– Keine Lust
Nov 24 '18 at 20:58
1
@KeineLust You are right, but in this loop i does not make a difference because i and j are both always equal.
– Werner Henze
Nov 24 '18 at 21:00
2
@WernerHenze, you are right, anyway the OP should know it
– Keine Lust
Nov 24 '18 at 21:04
@WernerHenze @ KeineLust thanks for help i will try to update the code
– hamza
Nov 24 '18 at 21:38
add a comment |
I want to find the index of the column and the row that contains the same number sequence in a 2D array.
for example
{2, 3, 2, 6}
{3, 6, 3, 10}
{7, 4, 2, 12}
{6, 8, 6, 4}
in this example, the program must return the line index 0 and the column index 2
I wrote a program using C language but it doesn't work
# include <stdio.h>
int main(){
char tab[3][3];
int simiLgn, simiClm;
for (int i = 0; i<3; i++){
for (int j = 0; j<3; j++){
printf("Tableau[%d][%d]=", i, j);
scanf("%d", &tab[i][j]);
}
}
for (int i = 0; i<3; i++){
for (int j = 0; j<3; j++){
printf("%d t", tab[i][j]);
}
printf("n");
}
int fix_lgn = 0;
int fix_col = 0;
while (fix_lgn<3){
while (fix_col<3){
for (int i=0, j=0; i<3, j<3 ; i++, j++){
if(tab[fix_lgn][j] == tab[i][fix_col]){
simiLgn = fix_lgn;
simiClm = fix_col;
}
else{
simiLgn = -1;
simiClm = -1;
}
}
fix_col++;
}
fix_col = 0;
fix_lgn++;
}
printf("ligne index: %dn", simiLgn);
printf("colonne index: %dn", simiClm);
return 0;
}
Thank you
c arrays
I want to find the index of the column and the row that contains the same number sequence in a 2D array.
for example
{2, 3, 2, 6}
{3, 6, 3, 10}
{7, 4, 2, 12}
{6, 8, 6, 4}
in this example, the program must return the line index 0 and the column index 2
I wrote a program using C language but it doesn't work
# include <stdio.h>
int main(){
char tab[3][3];
int simiLgn, simiClm;
for (int i = 0; i<3; i++){
for (int j = 0; j<3; j++){
printf("Tableau[%d][%d]=", i, j);
scanf("%d", &tab[i][j]);
}
}
for (int i = 0; i<3; i++){
for (int j = 0; j<3; j++){
printf("%d t", tab[i][j]);
}
printf("n");
}
int fix_lgn = 0;
int fix_col = 0;
while (fix_lgn<3){
while (fix_col<3){
for (int i=0, j=0; i<3, j<3 ; i++, j++){
if(tab[fix_lgn][j] == tab[i][fix_col]){
simiLgn = fix_lgn;
simiClm = fix_col;
}
else{
simiLgn = -1;
simiClm = -1;
}
}
fix_col++;
}
fix_col = 0;
fix_lgn++;
}
printf("ligne index: %dn", simiLgn);
printf("colonne index: %dn", simiClm);
return 0;
}
Thank you
c arrays
c arrays
edited Nov 25 '18 at 15:28
hamza
asked Nov 24 '18 at 20:54
hamzahamza
158
158
1
i<3, j<3this doesn't do what you think, switch toi<3 && j<3, and here:tab[fix_lgn, j]you wanttab[fix_lgn][j]
– Keine Lust
Nov 24 '18 at 20:58
1
@KeineLust You are right, but in this loop i does not make a difference because i and j are both always equal.
– Werner Henze
Nov 24 '18 at 21:00
2
@WernerHenze, you are right, anyway the OP should know it
– Keine Lust
Nov 24 '18 at 21:04
@WernerHenze @ KeineLust thanks for help i will try to update the code
– hamza
Nov 24 '18 at 21:38
add a comment |
1
i<3, j<3this doesn't do what you think, switch toi<3 && j<3, and here:tab[fix_lgn, j]you wanttab[fix_lgn][j]
– Keine Lust
Nov 24 '18 at 20:58
1
@KeineLust You are right, but in this loop i does not make a difference because i and j are both always equal.
– Werner Henze
Nov 24 '18 at 21:00
2
@WernerHenze, you are right, anyway the OP should know it
– Keine Lust
Nov 24 '18 at 21:04
@WernerHenze @ KeineLust thanks for help i will try to update the code
– hamza
Nov 24 '18 at 21:38
1
1
i<3, j<3 this doesn't do what you think, switch to i<3 && j<3, and here: tab[fix_lgn, j] you want tab[fix_lgn][j]– Keine Lust
Nov 24 '18 at 20:58
i<3, j<3 this doesn't do what you think, switch to i<3 && j<3, and here: tab[fix_lgn, j] you want tab[fix_lgn][j]– Keine Lust
Nov 24 '18 at 20:58
1
1
@KeineLust You are right, but in this loop i does not make a difference because i and j are both always equal.
– Werner Henze
Nov 24 '18 at 21:00
@KeineLust You are right, but in this loop i does not make a difference because i and j are both always equal.
– Werner Henze
Nov 24 '18 at 21:00
2
2
@WernerHenze, you are right, anyway the OP should know it
– Keine Lust
Nov 24 '18 at 21:04
@WernerHenze, you are right, anyway the OP should know it
– Keine Lust
Nov 24 '18 at 21:04
@WernerHenze @ KeineLust thanks for help i will try to update the code
– hamza
Nov 24 '18 at 21:38
@WernerHenze @ KeineLust thanks for help i will try to update the code
– hamza
Nov 24 '18 at 21:38
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53462272%2ffind-the-index-of-the-column-and-the-row-that-contains-the-same-number-sequence%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53462272%2ffind-the-index-of-the-column-and-the-row-that-contains-the-same-number-sequence%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
i<3, j<3this doesn't do what you think, switch toi<3 && j<3, and here:tab[fix_lgn, j]you wanttab[fix_lgn][j]– Keine Lust
Nov 24 '18 at 20:58
1
@KeineLust You are right, but in this loop i does not make a difference because i and j are both always equal.
– Werner Henze
Nov 24 '18 at 21:00
2
@WernerHenze, you are right, anyway the OP should know it
– Keine Lust
Nov 24 '18 at 21:04
@WernerHenze @ KeineLust thanks for help i will try to update the code
– hamza
Nov 24 '18 at 21:38