ARRAY PROBLMES

//Accept number from user and check where selected search number is in array or not and return the index of that number

//return statement not used in loop

#include<stdio.h>

#include<stdlib.h>

int CheckLastOccurance(int Arr[],int iSize,int iNo)

{

int i =0,index = -1;

for(i=0;i<iSize;i++)

{

if(Arr[i]==iNo)

{

index = i;

}

}

return index;

}

int main()

{

int iLength = 0;

int iValue = 0;

int i=0;

int *ptr = NULL;

int iRet = 0;

printf("Enter Number of elements\n");

scanf("%d",&iLength);

ptr = (int *)malloc(sizeof(int)* iLength);

printf("enter elements\n");

for(i=0;i<iLength;i++)

{

scanf("%d",&ptr[i]);

}

printf("Enter the element to search\n");

scanf("%d",&iValue);

printf("\n\n");

iRet= CheckLastOccurance(ptr,iLength,iValue);

if(iRet==-1)

{

printf("There is no such number\n");

}

else

{

printf("Number is there at index : %d\n",iRet);

}

//printf("Difference is : %d\n",iRet);

free(ptr);

return 0;

}