Advertisement
nguyenhappy92

Xóa tất cả các số lớn nhất trong mảng các số thực

Dec 8th, 2015
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. // Xoa tat ca cac so lon nhat mang so thuc
  2. // Khai bao cac ham thu vien neu co
  3. #include<stdio.h>
  4. #include<conio.h>
  5. #define SIZE 100
  6. void nhap(float a[],int &n)
  7. {
  8. scanf("%d",&n);
  9. float x;
  10. for(int i=0;i<n;i++)
  11. {
  12. scanf("%f",&x);
  13. a[i]=x;
  14. }
  15. }
  16. float timMax(float a[],int n)
  17. {
  18. float max=a[0];
  19. for(int i=0;i<n;i++)
  20. {
  21. if(a[i]>max)
  22. {
  23. max=a[i];
  24. }
  25. }
  26. return max;
  27. }
  28. void xoaPT(float a[],int &n,int k)
  29. {
  30. // k la vi tri can xoa
  31. for(int i=k;i<n;i++)
  32. {
  33. a[i]=a[i+1];
  34. }
  35. n--;
  36. }
  37. void xoalonnhat(float a[],int &n)
  38. {
  39. float soMax=timMax(a,n);
  40. for(int i=0;i<n;i++)
  41. {
  42. if(a[i]==soMax)
  43. {
  44. xoaPT(a,n,i);
  45. i--;
  46. }
  47. }
  48. }
  49. void xuat(float a[],int n)
  50. {
  51. for(int i=0;i<n;i++)
  52. {
  53. printf("%.2f",a[i]);
  54. }
  55. }
  56. void main()
  57. {
  58. float a[SIZE];
  59. int n;
  60. nhap(a,n);
  61. xoalonnhat(a,n);
  62. xuat(a,n);
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement