I made the C code of the statement:
I have already used the debug but I can not identify the reason for the error: Program received signal sigsegv segmentation fault I already changed and put in several ways the start random number generator, using NULL for example, but no use. srand (time (NULL)), below the code:Develop a program that simulates a ticketing system from a airline. The company has n flights, where in each of them there are m places available. The first m / 2 seats on each flight are reserved for non-smokers and the remainder for smokers.
Use an array of n rows per m columns to represent the seats of this company's flights. Initialize the array elements with zero to indicate that all seats on each of the n flights are available. As seats are being loaded assign 1 to the corresponding element of the array.
Must be randomly generated:
The number of flights. The number of tickets requested per flight. Whether the passenger is from the smoking or non-smoking area. The program should print at the end of the simulation: The average number of passengers per flight. The average number of passengers per area on each flight The average number of passengers not boarded for lack of seating (observe that there may be room on the plane, but there is no room in the requested area)
main() {
int n,m,p, i, j, matriz[n][m],f,assento_ocup,aux,fumantes,nao_fumantes;
float media_passageiros_voo, media_passageiros_area,media_pas_falta_assento,
media_passageiros_nao_fumantes_area, media_passageiros_fumantes_area;
time_t t;
// iniciar gerador de numeros aleatórios
srand((unsigned)time(&t));
//numero de voos-linhas
n=rand()%1+500;
//numero de lugares-colunas
m= rand()%1+100;
//numero de passagens solicitadas
p= rand()%1+100;
for(i=0; i<n; i++) { //linha-voos
for(j=0; j<m; j++){//coluna-passagens
matriz[n][m]=0;//todos assentos disponiveis
}
}
if(f%2==0){//se par nao e fumante
for(i=0; i<n; i++) {
for(j=0; j<m/2; j++){
matriz[i][j]=1;
nao_fumantes++;
}
}
}
else{ //e fumante
for(i=0; i<n; i++) {
aux=((m/2)+1);
for(j=aux; j<m; j++){
matriz[i][j]=1;
fumantes++;
}
}
}
for(i=0; i<n; i++) {
for(j=0; j<m; j++){
if(matriz[i][j]==1){
assento_ocup++;
}
}
}
media_passageiros_voo=assento_ocup/n;
media_pas_falta_assento= m-p;
media_passageiros_fumantes_area= fumantes/(m/2);
media_passageiros_nao_fumantes_area= nao_fumantes/(m/2);
printf("\n MEDIA DE PASSAGEIROS POR VOO:%.2f ",media_passageiros_voo);
printf("\n MEDIA DE PASSAGEIROS POR AREA EM CADA VOO: %.2f", media_passageiros_area);
printf("\n PASSAGEIROS NAO EMBARCADOS POR FALTA DE ASSENTO",media_pas_falta_assento);
getche();
}