Files
CSCI-1200/labs/debugging/main.cpp
2025-01-22 14:04:06 -05:00

42 lines
1018 B
C++

#include <iostream>
void compute_squares(unsigned int* a, unsigned int* b, int n) {
unsigned int* a_ptr = a;
unsigned int* b_ptr = b;
for (unsigned int i = 0; i < n; ++i) {
*b_ptr = (*a_ptr) * (*a_ptr);
a_ptr++;
b_ptr++;
}
}
int main() {
// Test Case 1
unsigned int a[] = {1, 2, 3, 4, 5};
unsigned int b[] = {0, 0, 0, 0, 0};
compute_squares(a, b, 5);
for (unsigned int i = 0; i < 5; ++i) {
std::cout << b[i] << " ";
}
std::cout << std::endl;
//Test Case 2
unsigned int c[] = {2, 4, 8, 16, 32};
unsigned int d[] = {0, 0, 0, 0, 0};
compute_squares(c, d, 5);
for (unsigned int i = 0; i < 5; ++i) {
std::cout << d[i] << " ";
}
std::cout << std::endl;
//Test Case 3
unsigned int e[] = {5, 4, 3, 2, 1};
unsigned int f[] = {0, 0, 0, 0, 0};
compute_squares(e, f, 5);
for (unsigned int i = 0; i < 5; ++i) {
std::cout << f[i] << " ";
}
std::cout << std::endl;
return 0;
}