Can someone help me with these C program problems? Thanks 1. Write a C program t
ID: 3684652 • Letter: C
Question
Can someone help me with these C program problems? Thanks
1. Write a C program that creates two arrays of integers, one on the stack and one on the heap. You will loop through these arrays and populate them with values (any value is fine). You will then loop through these arrays again and print each value. Your output should look something like “Value in index 1 is 100 from stack array and 100 from heap array.” Do not forget to print newlines. Do not forget to de-allocate any memory you allocate.
2. Write a program that allocates an array on the heap and then iterates through the heap using pointer arithmetic. Print the item as in part 2 at each iteration. Loop backwards through the array using pointer arithmetic and print as well.
Explanation / Answer
include<stdio.h>
int main() {
int i, array[50], num;
printf(" Please Enter number of elements :");
scanf("%d", &num);
//enter values into Array
printf(" Enter the values here :");
for (i = 0; i < num; i++) {
scanf("%d", &array[i]);
}
//This is to print all elements of array
for (i = 0; i < num; i++) {
printf(" arr[%d] = %d", i, array[i]);
}
createheap(array,num);
return (0);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.