Write a program to:
Use pointers to access array members.
#include <stdio.h>
void print(int *, size_t);
int main() {
int test1[5], test2[5], total[5];
printf("Test1:");
for (size_t i=0; i<5; i++)
scanf("%d", &test1[i]);
for (size_t i=0; i<5; i++)
scanf("%d", &test2[i]);
for (size_t i=0; i<5; i++)
total[i]=test1[i]+test2[i];
print(total, 5);
return 0;
}
void print(int *total, size_t n) {
for (size_t i=0; i<n; i++)
printf("%d ", total[i]);
printf("\n");
}
Comments
Leave a comment