我爲大小6的陣列的第一個元素被複制到變量與陣列多數元素。這將是非常有益的,如果有人可以指出
#include <stdio.h>
int main()
{
int arr[6],i,j,k,count=0;
printf("enter the nos");
for(i=0;i<=5;i++) //loop to accept values from the user
{
scanf("%d",&arr[i]);
}
for(i=0;i<=5;i++)
{
arr[i]=j; //the 1st element is assigned to j
for(k=0;k<=5;k++)
{
if(arr[k]==j)
{
count++; //whenever the required element is found in the array count is increased
}
}
if(count>=3)
{
printf("the majority elt is %d",j);
}
else
{
count=0; //if above conditions dont satisfy the count is again set to 0
}
//the inner loop after completing its iterations gives control to the outer loop
}
}
您的變量'j'從未初始化。 – Rabbid76
你顯示的代碼有什麼問題?你的問題是什麼?請[閱讀關於如何提出好問題](http://stackoverflow.com/help/how-to-ask)。 –