Suppose you have one array a[]=1,2,4,6 and a second array b[]=3,5,7. The merged result should have all the values, i.e. c[]=1,2,3,4,5,6,7. The merge should be done without using functions from <string.h>.
... |
|
#include int main () { int a[10],b[10],c[20]; int k,i,j; i=0; printf("Please enter first 10 digits: "); while (i<10) { scanf("%d", &a[i]); i++; } printf("Please enter second 10 digits: "); k=0; while (k<10) { scanf("c%d",&b[k]); k++; } j=0; while (j<10) { c[j]=a[i]; j++; } while (j<20) { c[j]=b[k]; j++; } j=0; while(j<20) { printf("%d\n", c[j]); } return 0; } |
Hello all. I'm having trouble merging arrays here. So first I allow the user to enter the size of the array, followed by the elements. Then I use a bubble sort to get them in ascending order. And I do this for two sets of values. But I can't seem to get them to merge. Please look at my code and ... |
i'm trying to Find the greatest product of five consecutive digits in the 1000-digit number. so i'll be looking at each index and doing this with a 1D array is easier. I'll use the 2D array if that's my last resort and I don't want to simply change the file so it'll be one long line that contains 1,000 digits. I ... |
Code: #include int merge_strings(char str1[], int index1,char str2[],int index2, char result[], int index3); int main() { char input[255]; char input2[255]; char result[510]; int index,flag,ch,lnd; printf("enter the first string \n"); for (index = 0; index < 254 && (ch = getchar()) != '\n' && ch >=0; ++index) { input[index] = ch; } input[index] = '\0'; printf("enter the second string \n"); for ... |
So basically, you don't have to store the merged arrays? And you want to ignore repeats... why not add the element from A providing if it's not in B to C, and the same for B (providing it's not in A) add it to C. Then order C... And output it. The max size of C will be, sizeof(A) + sizeof(B). ... |
|
Hello All, I have two arrays. Some elements are duplicated, it really depends on data length at runtime. I want to merge the arrays. Wondering, can anybody suggest me best method to merge the arrays. First algo comes to my mind is, 1. Sort one of the array. 2. Binary-search each element of second array in sorted array. 3. Place non-duplicated ... |
Code: #include #define ARRAY_LENGTH 7 #define ARRAY_B_LENGTH 5 #define ARRAY_A_LENGTH (ARRAY_B_LENGTH + ARRAY_LENGTH) int main() { int array_a[ARRAY_A_LENGTH]; int array_b[ARRAY_B_LENGTH]; int i, j; /* initialize or put value in arrays*/ for(i = 0, j = 47; i < ARRAY_LENGTH; i++) array_a[i] = i + j; for(i = 0, j = 53; i < ARRAY_B_LENGTH; i++) array_b[i] = i + j; /* ... |
#include #include #include #include using namespace std; #include void fnSortHeap(char array[], int arr_ubound); int main() { FILE *file; int i; int j=0; char fileparam[200] ; // char fileparam1[16] ; char arraytotal [1000]; int start =0 ; int k = 0 ; if(sprintf(fileparam, "in0.dat",i) ) { file = fopen(fileparam,"r"); if(file==NULL) { printf("Error: %s does not exist\n",fileparam); } ... |
Click to Expand / Collapse Quote originally posted by Joey_Brown ... Hello. I would very much appreciate if someone would aid me with a hint. My problem is as follows : read two arrays of chars and merge them into a third array like so : ARR1 :123abc ARR2: rt678iogl ARR3:1r2t36a7b8ciogl The problem must be solved without pointers and string.h ... |
|
hi guys...... i have a problem in writing a program of "how to delete the duplicate elements in an array" for example....if i enter an array like: 10 20 30 40 30 then it should print: 10 20 30 40 so could plz help me out????? :cry: i have attempted little though....but don't know how can i go ahead.... #include #include ... |