Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void main()
- {
- FILE *f = fopen("file.txt", "r");
- int s1, s2, s3;
- int *a1, *a2, *a3;
- fscanf(f, "%d", &s1);
- fscanf(f, "%d", &s2);
- s3 = s1 + s2;
- a1 = (int*)malloc(sizeof(int)*s1);
- a2 = (int*)malloc(sizeof(int)*s2);
- a3 = (int*)malloc(sizeof(int)*s3);
- printf("array 1 = ");
- for (int i = 0; i < s1; ++i)
- {
- fscanf(f, "%d", &a1[i]);
- printf("%d ", a1[i]);
- }
- printf("\narray 2 = ");
- for (int i = 0; i < s2; ++i)
- {
- fscanf(f, "%d", &a2[i]);
- printf("%d ", a2[i]);
- }
- int i = 0, j = 0, k = 0;
- while(k < s3)
- {
- if(i >= s1)
- a3[k++] = a2[j++];
- else if(j >= s2)
- a3[k++] = a1[i++];
- else if (a1[i] >= a2[j])
- a3[k++] = a2[j++];
- else if (a1[i] < a2[j])
- a3[k++] = a1[i++];
- }
- printf("\n-----------\nresult = ");
- for(int i = 0; i < s3; ++i)
- printf("%d ", a3[i]);
- fclose(f);
- free(a1);
- free(a2);
- free(a3);
- getchar();
- getchar();
- }
Advertisement
Add Comment
Please, Sign In to add comment