Adrita

task 1 ( ds lab 1) 3rd sem

Jan 7th, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #include<stdio.h>
  2. int main()
  3. {
  4. int a,ar[100],i,ar1[100],count=0,j,ar2[100],temp,temp1;
  5. for(i=0;;i++)
  6. {
  7. scanf("%d",&a);
  8. if(a>0)
  9. ar[i]=a;
  10. else
  11. break;
  12. }
  13. int len=i;
  14. for(i=1;i<10;i++)
  15. {
  16. for(j=0;j<len;j++)
  17. {
  18. if(ar[j]==i)
  19. count++;
  20. }
  21. ar1[i]=count;
  22. count=0;
  23. }
  24. for(i=0;i<10;i++)
  25. {
  26. ar2[i]=i;
  27. }
  28. for(i=0;i<len;i++)
  29. {
  30. for(j=0;j<len-i-1;j++)
  31. {
  32. if(ar1[j]<ar1[j+1])
  33. {
  34. temp=ar1[j];
  35. ar1[j]=ar1[j+1];
  36. ar1[j+1]=temp;
  37.  
  38. temp1=ar2[j];
  39. ar2[j]=ar2[j+1];
  40. ar2[j+1]=temp1;
  41. }
  42. }
  43. }
  44. for(i=0;i<=len;i++)
  45. {
  46. if(ar1[i]>0)
  47. printf("%d occurs: %d times\n",ar2[i],ar1[i]);
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment