Create a project called Daily20 Add a source file called dai

Create a project called Daily20. Add a source file called daily20.c into the project. In this exercise, you will practice working with an array of integers. Write a program that creates an integer array with 40 elements in it. Use a for loop to assign values of each element to the array so that each element has a value that is twice its index. For example the element with index 0 should have a value of 0, the element with index 1 should have a value of 2, the element with index 2 should have a value of 4 and so on. Once the array is initialized, output the array to the screen with 10 elements per line where each element is right justified in a column that is 7 characters wide. On the line after the array is printed, output a line that has 5 asterisks (\'*\') In It as a divider. Reverse the array elements in the array you created above, i.e., after reversal, the first element in the array should store 78, the second element should store 76 and the last element in the array should store 0. You may NOT use a second array to help your reversal. Then output the reversed array to the screen in the same way as above. This means that you are not asked to just output the initial array in the reversed order. Try to write a function to print the array and call it twice in your program. Your output should look something like the following:

Solution

#include<stdio.h>

int main() {
int arr[30], i, j, num, temp;

printf(\"\ Enter no of elements : \");
scanf(\"%d\", &num);

//Read elements in an array
for (i = 0; i < num; i++) {
scanf(\"%d\", &arr[i]);
}

j = i - 1; // j will Point to last Element
i = 0; // i will be pointing to first element

while (i < j) {
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
i++; // increment i
j--; // decrement j
}

//Print out the Result of Insertion
printf(\"\ Result after reversal : \");
for (i = 0; i < num; i++) {
printf(\"%d \\t\", arr[i]);
}

return (0);
}

 Create a project called Daily20. Add a source file called daily20.c into the project. In this exercise, you will practice working with an array of integers. Wr

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site