India's Largest Free Online Education Platform

C program to find the location address from given 1-D integer type array elements

C program to find the location address from given 1-D integer type array elements

#include <stdio.h>    // header files
#include <stdlib.h>
int main()  // main function 
{
 long int arr[100],BA,i,j,lb,n,Lc,ch;  // variable declaration
 lb=0;
 printf("\n This is a simple program to find the address from given 1-D integer type array elements\n");
 printf("\n Enter the lenth/size of arary that you are going to enter\n");
 scanf("%d",&n);
 
 printf("\n Enter the elemets\n");  // taking input as arrary elements 
  for(i=0;i<n;i++)
   {
   scanf("%d",&arr[i]);
   }
 
printf(" Your entered array elemets are-\n");  // printing entered array elements
   for(i=0;i<n;i++)
   {
     printf("\t %d",arr[i]);   
    }

 printf(" \n Choose an array element from above to find it's address\n");
 scanf("%d",&ch);
 
  for(i=0;i<n;i++)     // for loop
  {
    if(arr[i]==ch)
    j=i;
  }
 
 BA=arr;
 printf(" \n Base address of this array by program itself calculation is:%d\n",BA);

 Lc=(BA+(2*(j-lb)));   // formula to find the location address of 1-D array element
 printf("\nLocation of array element %d is :",ch);
 printf("%d",Lc,"\n");
return 0;
}  // end of main function


RESULT :  Output

C program to find the location address from given 1-D integer type array elements
C program to find the location address from given 1-D integer type array elements

The above code can’t be directly copy-pasted. You must have to type with your own hand. This is made for your better future. 

Are you made for copy paste?

Absolutely “NO”

Then, try hard to understand this code and type with your own.

Leave a Reply

Your email address will not be published. Required fields are marked *

error: Content is protected !!