Advertisement
nguyenhappy92

Tìm “số nguyên dương cuối cùng” trong mảng số thực

Nov 6th, 2015
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. // Tim gia tri so nguyen duong cuoi cung trong mang so thu
  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 duongcuoi(float a[],int n)
  17. {
  18. for(int i=n-1;i>=0;i--)
  19. {
  20. if(a[i]>0)
  21. return a[i];
  22. }
  23. return -1;
  24. }
  25. void main()
  26. {
  27. float a[SIZE];
  28. int n;
  29. nhap(a,n);
  30. printf("%.2f",duongcuoi(a,n));
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement