Advertisement
bernardolansing

array_compare

Jun 11th, 2021
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int array_compare(double *p1, double *p2, int comp1, int comp2) {
  4.  
  5. if (comp1 != comp2) return 0;
  6.  
  7. int i;
  8.  
  9. for (i = 0; i < comp1; i++)
  10. if (*(p1 + i) != *(p2 + i)) return 0;
  11.  
  12. return 1;
  13. }
  14.  
  15. int main() {
  16. double array1[] = {1,2,3,4,5}, array2[] = {1,2,3,4,5};
  17. double array3[] = {1,2,3,4,5}, array4[] = {4,5,6,7,8};
  18. double array5[] = {1,2,3,4,5}, array6[] = {1, 2, 3};
  19.  
  20. if (array_compare(array1, array2, 5, 5)) printf("1");
  21. if (array_compare(array3, array4, 5, 5)) printf("2");
  22. if (array_compare(array5, array6, 5, 3)) printf("3");
  23.  
  24. return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement