Linear search in c , get array size


# include  <stdio.h>
# define NELEMS(arr) (sizeof(arr) / sizeof(arr[0])) // macro to calculate array size

int main(int argc, char *argv[]){
 int key, linear_arr[100], arr_size, i;

 //key = get_random(100);
 key = 16;
 printf("key===>%d\n",key );
 arr_size = NELEMS(linear_arr);

 //loop to generate array of randome numbers
 for(i=0; i< arr_size; i++ ){
  linear_arr[i] = get_random(100);
  printf("%d, ",linear_arr[i] );

 //loop to linear search array for key
 for(i=0; i< arr_size; i++ ){
    if (key == linear_arr[i]){
      printf("\nkey found----%d\n", key);

//to generate random number 
int get_random(int limit){
  return rand() % limit ;

I am Senior Software Engineer. I love reading, writing, sharing,developing, hiking, movies, trips, mountains, brooks, hills etc.

Tagged with: ,
Posted in c language, Parallel Programming

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: