Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main()
- {
- FILE *fp, *fd, *fv;
- fp = fopen("cisla1.txt","r");
- fd = fopen("cisla2.txt","r");
- fv = fopen("vysledok.txt","w");
- int cisla, x=0,y=0,i=0,j=0;
- int pole1[10000], pole2[10000];
- while(fscanf(fp,"%d",&cisla)>0)
- {
- pole1[x++] = cisla;
- }
- while(fscanf(fd,"%d",&cisla)>0)
- {
- pole2[y++] = cisla;
- }
- while(1)
- {
- if(j==y)
- {
- while(i!=x)
- {
- fprintf(fv, "%d ", pole1[i++]);
- }
- }
- if(i==x)
- {
- while(j!=y)
- {
- fprintf(fv, "%d ", pole2[j++]);
- }
- }
- if( (x==i) && (y==j) )
- {
- break;
- }
- if(pole1[i] < pole2[j])
- {
- fprintf(fv, "%d ", pole1[i++]);
- }
- else if(pole1[i] > pole2[j])
- {
- printf("%d %d", pole1[i], pole2[y]);
- fprintf(fv, "%d ", pole2[j++]);
- }
- else if(pole1[i] == pole2[j])
- {
- fprintf(fv, "%d ", pole1[i++]);
- fprintf(fv, "%d ", pole2[j++]);
- }
- }
- fclose(fp);
- fclose(fd);
- fclose(fv);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement