Advertisement
nguyenhappy92

Tính giá trị lớn nhất trong mảng số thực

Oct 14th, 2015
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. // tinh gia trij nho nhat trong mang so thuc
  2. // Khai bao cac ham thu vien neu cos
  3. #include<stdio.h>
  4. #include<conio.h>
  5. #define SIZE 100
  6. void nhap(float a[],int &n);
  7. float max(float a[],int n);
  8. void main()
  9. {
  10. float a[SIZE];
  11. int n;
  12. nhap(a,n);
  13. float t=max(a,n);
  14. printf("%.2f",t);
  15. }
  16. void nhap(float a[],int &n)
  17. {
  18. scanf("%d",&n);
  19. float x;
  20. for(int i=0;i<n;i++)
  21. {
  22. scanf("%f",&x);
  23. a[i]=x;
  24. }
  25. }
  26. float max(float a[],int n)
  27. {
  28. float lonnhat=a[0];
  29. for(int i=0;i<n;i++)
  30. {
  31. if(a[i]>lonnhat)
  32. lonnhat=a[i];
  33. }
  34. return lonnhat;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement