add solution of lab02
This commit is contained in:
42
labs/debugging/main.cpp
Normal file
42
labs/debugging/main.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user