0
To simplify, I have to make this ex:
**Write a program that reads two sequences of ten integer numbers and prints on screen how many of these numbers are present in the two sequences and how many occurrences there are identical numbers in the same position as the two sequences. For example, for the following sequences: 1 20 102 42 37 20 11 53 11 1 11 20 1000 1110 532 42 37 87 87 1 The program should print on the screen: There are 5 numbers present in both sequences There are 2 occurrences of numbers at the same position of the two sequences.
Note that numbers 1, 20, 42, 37 and 11 appear in both sequences (5 numbers common in both sequences). In the second position of both sequences we have the number 20 and at last position the number 1 (i.e., 2 occurrences of numbers in it position).**
And here’s my code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int l,c,k,m,cRepetido,nRepetido,var[10],var2[10];
int seq[2][10];
nRepetido=0;
cRepetido=0;
int verificado[c];
printf("Digite os numeros da sequencia 1 \n");
for(l=0;l<2;l++){
for(c=0;c<10;c++){
printf("[%d][%d]\n",l,c);
scanf("%d",&seq[l][c]);
}
}
for(l=0;l<2;l++){
for(c=0;c<10;c++){
if(seq[0][l]==seq[1][c]&&var[c]!=seq[1][c]){
var[c]=seq[l][c];
nRepetido++;
}
}
}
for(l=0;l<2;l++){
for(c=0;c<10;c++){
if(seq[0][c]==seq[1][c]&&var2[c]!=seq[0][c]){
var2[c]=seq[0][c];
cRepetido++;
}
}
}
printf("Existem %d Repetições nas linhas\n",nRepetido);
printf("Existem %d Repeticoes nas Colunas",cRepetido);
return 0;
}
Okay, you’ve entered the statement and the code you’ve made so far. What’s wrong with your code? Make it easy for those who will help you by creating an answer. Try creating a more general question that is not a "do this exercise for me" so other people can benefit from your question in the future when they have a similar problem.
– Rafael Tavares
You test arrays position
var
andvar2
without having assigned anything to them. The test will be against memory junk. Note that numbers that eventually repeat should be counted only once.– anonimo