C
Programming and Technical
Programming
Program
find out the element from an array of numbers which repeats most number of time.
i.e if the array is {1,2,2,2,3} ans is {2}
if the array is {1,2,2,2,3,3,3} ans is {2,3}
Read Solution (Total 4)
-
- Use two loops. In the outer loop, pick elements one by one and count the number of occurrences of the picked element in the inner loop.
This method doesn’t use the other useful data provided in questions like range of numbers is between 1 to n and there are only two repeating elements.
#include
#include
void printRepeating(int arr[], int size)
{
int i, j;
printf(" Repeating elements are ");
for(i = 0; i < size; i++)
for(j = i+1; j < size; j++)
if(arr[i] == arr[j])
printf(" %d ", arr[i]);
}
int main()
{
int arr[] = {4, 2, 4, 5, 2, 3, 1};
int arr_size = sizeof(arr)/sizeof(arr[0]);
printRepeating(arr, arr_size);
getchar();
return 0;
} - 10 years agoHelpfull: Yes(3) No(0)
- #include
#include
void main()
{
clrscr();
int array1[10]={0},s,p;
printf("enter the no of elements in an array n");
scanf("%d",&s);
printf("enter the elements in arrayn");
for(p=0;p - 10 years agoHelpfull: Yes(2) No(8)
- ans is 2 because we see only the first number which occurs maximum times
- 10 years agoHelpfull: Yes(1) No(1)
- my answer is 9 this can be explain with small example so that u can easily understand ++i will increment the value of i, and then return the incremented value.
i = 1;
j = ++i;
(i is 2, j is 2)
i++ will increment the value of i, but return the original value that i held before being incremented.
i = 1;
j = i++;
(i is 2, j is 1)
- 10 years agoHelpfull: Yes(0) No(1)
C Other Question