By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,440 Members | 1,420 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,440 IT Pros & Developers. It's quick & easy.

problem with arrays

P: 22
could u pls guys help me with this problem
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define MIN_SIZE1 20
  4. #define MIN_SIZE2 20
  5. #define MAX_SIZE 40
  6.  
  7. int populate_an_array(int array[], int array_size);
  8. void remove_duplicates(int array[], int array_size);
  9. void sort_array(int array[],int array_size);
  10. int merge_the_contents(int array[],int array_size,int arr2,int array_size2,int result[]);
  11. int search_value(int array[],int array_size,int number);
  12.  
  13. int main()
  14. {
  15.     int array1[MIN_SIZE1];
  16.     int array2[MIN_SIZE2];
  17.     int number;
  18.     int result_arr[MIN_SIZE1+MIN_SIZE2];
  19.     int i;
  20.  
  21.  
  22. populate_an_array(array1, MIN_SIZE1);
  23. populate_an_array(array2, MIN_SIZE2);
  24.  
  25.     remove_duplicates(array1, MIN_SIZE1);
  26.     remove_duplicates(array2, MIN_SIZE2);
  27.  
  28. sort_array(array1, MIN_SIZE1);
  29. sort_array(array2, MIN_SIZE2);
  30.  
  31.     merge_the_contents(array1,MIN_SIZE1,array2, MIN_SIZE2,result_arr);
  32.  
  33.  
  34.  
  35.     remove_duplicates(result_arr,(MIN_SIZE1+MIN_SIZE2));
  36.     sort_array(result_arr,(MIN_SIZE1+MIN_SIZE2));
  37.     for(i=0;i<MAX_SIZE;i++)
  38.     {printf("%d,\n", result_arr[i]);
  39.         }
  40.         printf("enter the number");
  41.         scanf("%d\n",&number);
  42.  
  43.             search_value(result_arr,(MIN_SIZE1+MIN_SIZE2),number);
  44.  
  45. return 0;
  46. }
  47. int populate_an_array(int array[], int array_size)
  48. {
  49.     int i;
  50.     randomize();
  51.     for (i=0;i<array_size;i++)
  52.     {array[i]=rand()%100;}
  53.     return *array;
  54.     }
  55.  
  56.  
  57.     int remove_duplicate(int array[],int array_size)
  58.     {
  59.     int i,j;
  60.     for (i= 0;i<array_size;i++)
  61.     {
  62.         for(j =0;j =array_size;j++)
  63.         {
  64.             if (j !=i){
  65.             if (array[i]=array[j]){
  66.                 array[j] =rand()%100;
  67.                 }
  68.             }
  69.         }
  70.     }
  71.  
  72.         return *array;
  73. }
  74.  
  75.  
  76. void sort_array(int array[], int array_size)
  77.     {
  78.     int i,j,temp;
  79.  
  80.  
  81.             for(i=0;i< array_size-1;i++)
  82. for(j=i+1;j<array_size;j++){
  83. if(array[i]>array[j]){
  84.     temp=array[i];
  85.     array[i]=array[j];
  86.     array[j] =temp;
  87.     }
  88. }
  89. }
  90.  
  91. int merge_the_contents(int array[],int array_size,int arr2,int array_size2,int result[])
  92. {
  93. int i,j;
  94.  
  95. for(i=0;i<array_size;i++)
  96. {
  97. result[i]=array[i];
  98.     }
  99.     for (j=0;j<array_size;j++)
  100.     {
  101.     result[(array_size2 + j)] = arr2[j];
  102.     }
  103.     return *result;
  104. }
  105.  
  106.      int search_value(int array[],int array_size,int number){
  107.  
  108. int low = 0, high = array_size, mid,found=0;
  109.  
  110.  
  111. while (low < high) {
  112.     mid = (low + high) / 2;
  113.     if (array[mid] < number)
  114.         low = mid + 1;
  115.      else
  116.           high = mid;
  117.      }
  118.      if(found==1)
  119.          printf("the number is \"%d\" is found",number);
  120.      else
  121.          printf("the number \"%d\" is not found",number);
  122.  
Mar 16 '07 #1
Share this Question
Share on Google+
8 Replies


Expert 100+
P: 1,510
for a start
Expand|Select|Wrap|Line Numbers
  1. int merge_the_contents(int array[],int array_size,int arr2,int array_size2,int result[])
  2.  
should parameter 3 be an int[], e.g.
Expand|Select|Wrap|Line Numbers
  1. int merge_the_contents(int array[],int array_size,int arr2[],int array_size2,int result[])
  2.  
Mar 16 '07 #2

P: 22
for a start
Expand|Select|Wrap|Line Numbers
  1. int merge_the_contents(int array[],int array_size,int arr2,int array_size2,int result[])
  2.  
should parameter 3 be an int[], e.g.
Expand|Select|Wrap|Line Numbers
  1. int merge_the_contents(int array[],int array_size,int arr2[],int array_size2,int result[])
  2.  
thanks man but there is one error:
Call to function 'search_value' with no prototype in function main.I JUST CANT FIGURE OUT WHAT TO DO
Mar 16 '07 #3

Expert 100+
P: 1,510
thanks man but there is one error:
Call to function 'search_value' with no prototype in function main.I JUST CANT FIGURE OUT WHAT TO DO
I don't get that error - there is prototype at the top of the program
Expand|Select|Wrap|Line Numbers
  1. int search_value(int array[],int array_size,int number);
  2.  
I get a [Linker error] undefined reference to `remove_duplicates' and `randomize'
Mar 16 '07 #4

P: 22
I don't get that error - there is prototype at the top of the program
Expand|Select|Wrap|Line Numbers
  1. int search_value(int array[],int array_size,int number);
  2.  
I get a [Linker error] undefined reference to `remove_duplicates' and `randomize'
now i get a syntax error for :
int search_value(int array[],int array_size,int number);
Mar 16 '07 #5

Expert 100+
P: 1,510
now i get a syntax error for :
int search_value(int array[],int array_size,int number);
very strange - taking the code in your first post I fix the line
Expand|Select|Wrap|Line Numbers
  1. int merge_the_contents(int array[],int array_size,int arr2[],int array_size2,int result[])
and it compiles OK with [Linker error] undefined reference to `remove_duplicates' and `randomize'

what compiler are you using?
Mar 16 '07 #6

P: 22
very strange - taking the code in your first post I fix the line
Expand|Select|Wrap|Line Numbers
  1. int merge_the_contents(int array[],int array_size,int arr2[],int array_size2,int result[])
and it compiles OK with [Linker error] undefined reference to `remove_duplicates' and `randomize'

what compiler are you using?
i am using SCITE-A SCINTILLA BASED TEXT EDITOR
Mar 16 '07 #7

P: 22
i am using SCITE-A SCINTILLA BASED TEXT EDITOR
i have done again but it cant compile well:
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define MIN_SIZE1 20
  4. #define MIN_SIZE2 20
  5. #define MAX_SIZE 40
  6.  
  7. int populate_an_array(int array[], int array_size);
  8. void remove_duplicates(int array[], int array_size);
  9. void sort_array(int array[],int array_size);
  10. int merge_the_contents(int array[],int array_size,int arr2[],int array_size2,int result[]);
  11. int search_value(int array[],int array_size,int number);
  12.  
  13. int main()
  14. {
  15.     int array1[MIN_SIZE1];
  16.     int array2[MIN_SIZE2];
  17.     int number;
  18.     int result_arr[MIN_SIZE1+MIN_SIZE2];
  19.     int i;
  20.  
  21.  
  22. populate_an_array(array1, MIN_SIZE1);
  23. populate_an_array(array2, MIN_SIZE2);
  24.  
  25.     remove_duplicates(array1, MIN_SIZE1);
  26.     remove_duplicates(array2, MIN_SIZE2);
  27.  
  28. sort_array(array1, MIN_SIZE1);
  29. sort_array(array2, MIN_SIZE2);
  30.  
  31.     merge_the_contents(array1,MIN_SIZE1,array2, MIN_SIZE2,result_arr);
  32.  
  33.  
  34.  
  35.     remove_duplicates(result_arr,(MIN_SIZE1+MIN_SIZE2));
  36.     sort_array(result_arr,(MIN_SIZE1+MIN_SIZE2));
  37.     for(i=0;i<MAX_SIZE;i++)
  38.     {printf("%d,\n", result_arr[i]);
  39.         }
  40.         printf("enter the number");
  41.         scanf("%d\n",&number);
  42.  
  43.             search_value(result_arr,(MIN_SIZE1+MIN_SIZE2),number);
  44.  
  45. return 0;
  46. }
  47. int populate_an_array(int array[], int array_size)
  48. {
  49.     int i;
  50.     randomize();
  51.     for (i=0;i<array_size;i++)
  52.     {array[i]=rand()%100;}
  53.     return *array;
  54.     }
  55.  
  56.  
  57.     int remove_duplicate(int array[],int array_size)
  58.     {
  59.     int i,j;
  60.     for (i= 0;i<array_size;i++)
  61.     {
  62.         for(j =0;j<array_size;j++)
  63.         {
  64.             if (j !=i)
  65.             {
  66.             if (array[i]=array[j])
  67.                 {
  68.                 array[j] =rand()%100;
  69.                 }
  70.             }
  71.         }
  72.     }
  73.  
  74.         return *array;
  75. }
  76.  
  77.  
  78. void sort_array(int array[], int array_size)
  79.     {
  80.     int i,j,temp;
  81.  
  82.  
  83.             for(i=0;i< array_size-1;i++)
  84. for(j=i+1;j<array_size;j++){
  85. if(array[i]>array[j]){
  86.     temp=array[i];
  87.     array[i]=array[j];
  88.     array[j] =temp;
  89.     }
  90. }
  91. }
  92.  
  93. int merge_the_contents(int array[],int array_size,int arr2[],int array_size2,int result[])
  94. {
  95. int i,j;
  96.  
  97. for(i=0;i<array_size;i++)
  98. {
  99. result[i]=array[i];
  100.     }
  101.     for (j=0;j<array_size;j++)
  102.     {
  103.     result[(array_size2 + j)] = arr2[j];
  104.     }
  105.     return *result;
  106. }
  107.  
  108.      int search_value(int array[],int array_size,int number){
  109.  
  110. int low = 0, high = array_size, mid,found=0;
  111.  
  112.  
  113. while (low < high) {
  114.     mid = (low + high) / 2;
  115.     if (array[mid] < number)
  116.         low = mid + 1;
  117.      else
  118.           high = mid;
  119.      }
  120.      if(found==1)
  121.          printf("the number is \"%d\" is found",number);
  122.      else
  123.          printf("the number \"%d\" is not found",number);
  124.  return 0;}
Mar 16 '07 #8

Ganon11
Expert 2.5K+
P: 3,652
Please don't post again on the same topic - you may continue to receive help in this thread. A second thread is not necessary.
Mar 16 '07 #9

Post your reply

Sign in to post your reply or Sign up for a free account.