Advertisement
nguyenhappy92

Tìm giá trị âm đầu tiên trong mảng một chiều các số âm thực

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