Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need it done in C. Write a program that asks the user for an integer value gre

ID: 3574252 • Letter: I

Question

I need it done in C.

Write a program that asks the user for an integer value greater than zero. It will verify that the user has entered a valid value and then try to allocate enough space using mallow function for an array of integers with N elements where N is the integer they entered in the first step. Your program should make sure that the allocation worked and then use a for loop and the square brackets operator to give every integer variable location in the dynamically allocated array the value of its index plus For example the variable that is zero element away from the base address should get the value 1, the value that is 1 element away from the base address should get the value 2 and so on (see the screen shot below). When you have initialized all the values use another for loop and the square bracket operator to print them in reverse order (just print them in reversed order) separated by new lines. Print a line that has 3 asterisks in it by itself and then use another for loop that prints all of the array elements in order but without using the square bracket operator. To do this you will need to use only the dereference operator and pointer arithmetic (i.e., increment or decrement the pointer). Don't forget to free the memory before the program ends. Your program output should look something like the following:

Explanation / Answer

#include<stdio.h>
#include<conio.h>
#include<alloc.h>
void main()
{
   int n,p*,i,j,*q;
clrscr();
printf("please enter the number of elements of your dynamic array:");
scanf("%d",&n);
     if(n>0)
     {
      p= (int *) malloc (sizeof(int)*n);
          if(p==NULL)
          {
           printf("memory allocation not possible")
           exit();
           }
        for (i=0;i<n;i++)
       {
  j=i;
  printf(" Element at index %d :",i);
  *(p+i)=j+1;
  q=p+i;
}
      }
/* to display in reverse order*/
for (i=0;i<n;i++)
       {
  printf(" Element at index %d :%d",i,*(q-i));
  

}
printf(" ***");

/* to display in same order*/
for (i=0;i<n;i++)
       {
  printf(" Element at index %d :%d",i,*(p+i));
  

}
free (p);
getch();
}