1
I’ve been trying to solve a problem since early on:
A school wants to know if there are students attending simultaneously disciplines Logic and and Programming Language. Put the numbers of the enrollments of students who study Logic in a vector, at most of 5 students. Enter the enrollment numbers of the students who attend Language in another vector, maximum of 5 students. Show the number of number plate that appears on the two vectors.
It’s even running but when I put numbers out of order it’s bugging. If you can help me thank you, because I am breaking my head on this issue and it is holding me to finish the rest of the others, seems to be lazy to think, but I am early caught in this issue.
Thank you in advance
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
int i, a;
int mat1[6], mat2[6];
int main(void){
setlocale(LC_ALL, "Portuguese");
for(i=0 ; i<5; i++){
printf("DIGITE AS MATRÍCULAS DOS ALUNOS DE LÓGICA DE PROGRAMAÇÃO: ");
scanf("%d", &mat1[i]);
}
printf("\n");
for(i=0; i<5; i++){
printf("DIGITE AS MATRÍCULAS DOS ALUNOS DE LINGUAGEM DE PROGRAMAÇÃO: ");
scanf("%d", &mat2[i]);
}
printf("\n");
for(i=0; i<5; i++){
for(a=5; a>=0; a--)
{
if(mat1[i] == mat2[a] || mat1[a] == mat2[i]) printf("AS MATRÍCULAS IGUAIS SÃO: %d\n", mat1[i]);
}
}
return 0;
}
Running the program:
you need to "sort" or "sort" the arrays before making the comparison...how to make the comparison ? there is a library function called "qsort" that does this...if you find it very difficult to use "qsort", do the sorting manually, using for example the algorithm "Bubble Sort"...and where to find information about "qsort" and "Bubble Sort"? google...
– zentrunix