Jump to content

Procura num vector


Upper

Recommended Posts

Eu tenho ate agora este codigo

void frequencia(int num,int var[]){

int i,j;
int control=0;
float total;


	for(i=0;i<num;i++)
	{
		printf("Qual e o numero %d: ",i+1);
		scanf("%d", &var[i]);
	}	
	getchar();


printf("\nO numero de elementos inseridos sao %d\n",i);

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

	if(var[i]==j){
		control++;
		i++;
	}
	else{
		i++;
	}
}
		total=control/i;
	for(i=0;i<num;i++){printf("A frequencia de elementos com o numero %d e: %d\n",i+1,total);  
   }
  }

so que se eu poser por exemplo so 2 elementos no final no ultimo printf ele so verifica o numero 1 e 2. Qual e o erro?

Link to comment
Share on other sites

ja descobri o erro...so que nao me ta a aparecer nenhum valor no total....ps codigo corrigido:


int frequencia(int num,int var[]){

int i,j;
int control=0;
float total=0;


	for(i=0;i<num;i++)
	{
		printf("Qual e o numero %d: ",i+1);
		scanf("%d", &var[i]);
	}	
	getchar();


printf("\nO numero de elementos inseridos sao %d\n",i);

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

	if(var[i]==j)
	{
		control++;
		i++;
	}
	else{i++;}
}
		total=control/i;
	for(i=0;i<9;i++){printf("A frequencia de elementos com o numero %d e: %f\n",i+1,total);}
}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.