int main(void) { int n, i; int countVector; // function comp_vec passes the count to this printf("Enter the length of the two vectors\n"); scanf("%d", &n); int v1[n], v2[n], v3[n]; // initalize array elements after index is grabbed from user printf("Enter %d numbers for the first array\n", n); // fill arrays for (i = 0; i < n; i++) { scanf("%d", &v1[i]); } printf("Enter %d numbers for the second array\n", n); for (i = 0; i < n; i++) { scanf("%d", &v2[i]); } multi_vec(v1, v2, v3, n); // perform dot product on array elements printf("The multiplication of the vectors is: "); for (i = 0; i < n; i++) { // fill new array printf("%d ", v3[i]); } printf("\n"); countVector = comp_vec(v1, v2, n); // compare the count from comp_vec to the index n if ( countVector == n ) // if they are the same then both the arrays are the same printf("The vectors are the same \n"); // else they are different else printf("The vectors are different \n"); return 0; }
int main(void) { int n; int *i; printf("Enter length of the vectors: \n"); scanf("%d\n", &n); int a[n]; int b[n]; printf("Enter the first vector: \n"); for (i = a; i < a + n; i++) /* fill vector one with pointer arithmetic */ { scanf("%d\n", &*i); } printf("Enter the second vector: \n"); for (i = b; i < b + n; i++) /* fill vector two with pointer arithmetic */ { scanf("%d\n", &*i); } int c[n]; multi_vec(a, b, c, n); /* multiply the two vectors a and b storing the resulting vector in array c */ int result = comp_vec(a, b, n); /* compare vectors a and b to see if the same return 1 if same else 0 */ printf("The multiplication of the vectors is:"); for (i = c; i < c + n; i++) /* print result of multiplication */ { printf(" %d", *i); } printf("\n"); if(result == 1) { printf("The vectors are the same\n"); } else { printf("The vectors are not the same\n"); } return 0; }
int main(){ Solution sol; TreeNode root = TreeNode(1); TreeNode lft = TreeNode(2); TreeNode rgt = TreeNode(3); TreeNode llft = TreeNode(4); TreeNode lrgt = TreeNode(5); root.left = &lft; root.right = &rgt; lft.left = &llft; lft.right = &lrgt; vector<int> result; int NumArray[] = {4,5,2,3,1}; result =sol.postorderTraversal(&root); std::vector<int> exact (NumArray,NumArray + sizeof(NumArray)/ sizeof(int)) ; leettest(comp_vec(result,exact)==0); return 0; }