Advertisement
nguyenhappy92

Viết hàm tìm “số chẵn đầu tiên” trong mảng các số nguyên

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