GerexD

gy40 / 6,7,8

May 22nd, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. 6
  2.  
  3.  
  4. #include <iostream>
  5. #include <fstream>
  6. /**6. Olvassunk be a billentyûzetrôl egy n természetes számot, majd írjuk ki a piramis.out fájlba a következô számokat:
  7. 1
  8. 1 2
  9. 1 2 3
  10. 1 2 3 4
  11. ......
  12. 1 2 3 4 5 ... n-1 n*/
  13. using namespace std;
  14.  
  15. int main()
  16. {
  17. ofstream f("piramos.out.txt");
  18. int n,a[50][50];
  19. cout<<"N ";cin>>n;
  20. for(int i=1;i<=n;i++)
  21. {
  22. for(int j=1;j<=n;j++)
  23. a[i][j]=j;
  24. }
  25. for(int i=1;i<=n;i++)
  26. {
  27. for(int j=1;j<=n;j++)
  28. {
  29. while(j!=i) f<<a[i][j]<<" ";
  30. }
  31. cout<<endl;
  32. }
  33.  
  34. return 0;
  35. }
  36. ++++++++++++++++++++++++++++++++++++++++++++++++
  37. 7
  38.  
  39.  
  40.  
  41. #include <iostream>
  42. #include <fstream>
  43. ///7. Ird meg azt a programot, amely a billentyûzetrôl beolvas egy nem nulla természetes számot(n<1000),
  44. /// majd létrehozza a bac.txt állományt, amelynek elsô sorába írja az n osztóit csökkenô sorrendben, szóközzel elválasztva egymástól.
  45. ///Pl. ha n=10, akkor a bac.txt állomány tartalma: 10 5 2 1
  46. using namespace std;
  47.  
  48. int main()
  49. {
  50. int n,m=1, a[50];
  51. cout<<"N ";cin>>n;
  52. ofstream f("bac.txt");
  53.  
  54. for(int i=n;i>=1;i--)
  55. {
  56. if(n%i==0)
  57. {
  58. a[m]=i;
  59. m++;
  60. }
  61. }
  62. for(int i=1;i<m;i++)f<<a[i]<<" ";
  63.  
  64. return 0;
  65. }
  66. ++++++++++++++++++++++++++++++++++++++++++++++++
  67. 8
  68.  
  69.  
  70. #include <iostream>
  71. #include <fstream>
  72. /**8. Irjuk az elsô n páros számot a parosok.txt állományba. Az állomány minden sora 15 számot tartalmazzon, kivéve az utolsó sort.*/
  73. using namespace std;
  74.  
  75. int main()
  76. {
  77. int n,a[50][50],m=1,q=1,i=1,j=1;
  78. ofstream f("parosok.txt");
  79.  
  80. cout<<"N ";cin>>n;
  81.  
  82. while(m!=n)
  83. {
  84. if(q%2==0)
  85. {a[i][j]=q;
  86. j++;}
  87. q++;
  88. if(j==15)
  89. {
  90. j=1;
  91. i++;
  92. }
  93. }
  94. for(int i=1;i<=n;i++)
  95. {
  96. for(int j=1;j<=n;j++) f<<a[i][j]<<" ";
  97. f<<endl;
  98.  
  99. }
  100. return 0;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment