Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int main()
- {
- int i,j,n,half,count;
- scanf("%d",&n);
- int ara[n];
- half=n/2;
- for(i=0;i<n;i++)
- {
- scanf("%d",&ara[i]);
- }
- for(i=0;i<n;i++)
- {
- count=0;
- for(j=0;j<n;j++)
- {
- if(ara[i]==ara[j])
- {
- count++;
- }
- }
- if(count>half)
- {
- printf("%d is the majority element\n",ara[i]);
- return 0;
- }
- }
- printf("There is no majority element\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement