Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5.  
  6. FILE *fp, *fd, *fv;
  7.  
  8.  
  9. fp = fopen("cisla1.txt","r");
  10. fd = fopen("cisla2.txt","r");
  11. fv = fopen("vysledok.txt","w");
  12. int cisla, x=0,y=0,i=0,j=0;
  13. int pole1[10000], pole2[10000];
  14.  
  15. while(fscanf(fp,"%d",&cisla)>0)
  16. {
  17. pole1[x++] = cisla;
  18. }
  19. while(fscanf(fd,"%d",&cisla)>0)
  20. {
  21. pole2[y++] = cisla;
  22. }
  23.  
  24.  
  25.  
  26. while(1)
  27. {
  28. if(j==y)
  29. {
  30. while(i!=x)
  31. {
  32. fprintf(fv, "%d ", pole1[i++]);
  33. }
  34. }
  35. if(i==x)
  36. {
  37. while(j!=y)
  38. {
  39. fprintf(fv, "%d ", pole2[j++]);
  40. }
  41. }
  42.  
  43. if( (x==i) && (y==j) )
  44. {
  45. break;
  46. }
  47.  
  48. if(pole1[i] < pole2[j])
  49. {
  50. fprintf(fv, "%d ", pole1[i++]);
  51. }
  52. else if(pole1[i] > pole2[j])
  53. {
  54. printf("%d %d", pole1[i], pole2[y]);
  55. fprintf(fv, "%d ", pole2[j++]);
  56. }
  57. else if(pole1[i] == pole2[j])
  58. {
  59. fprintf(fv, "%d ", pole1[i++]);
  60. fprintf(fv, "%d ", pole2[j++]);
  61. }
  62.  
  63.  
  64.  
  65. }
  66.  
  67.  
  68. fclose(fp);
  69. fclose(fd);
  70. fclose(fv);
  71.  
  72.  
  73. return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement