Advertisement
Guest User

Untitled

a guest
Mar 30th, 2015
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int main()
  4. {
  5. int i,j,n,half,count;
  6. scanf("%d",&n);
  7. int ara[n];
  8. half=n/2;
  9. for(i=0;i<n;i++)
  10. {
  11. scanf("%d",&ara[i]);
  12. }
  13. for(i=0;i<n;i++)
  14. {
  15. count=0;
  16. for(j=0;j<n;j++)
  17. {
  18. if(ara[i]==ara[j])
  19. {
  20. count++;
  21. }
  22. }
  23. if(count>half)
  24. {
  25. printf("%d is the majority element\n",ara[i]);
  26. return 0;
  27. }
  28. }
  29. printf("There is no majority element\n");
  30. return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement