Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. #include <cmath>
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <cstdlib>
  5. #include <time.h>
  6.  
  7. //bąbelkowe
  8.  
  9. using namespace std;
  10.  
  11. int main()
  12. {
  13. int N;
  14. cout <<"Ile losowych liczb chcesz posortowac?";
  15. cin >> N;
  16.  
  17. int tab[N],i,j;
  18.  
  19. srand((unsigned)time(NULL));
  20.  
  21. for(i = 0; i < N; i++)
  22. tab[i] = rand() % 100;
  23. for(i = 0; i < N; i++)
  24.  
  25. cout << " " << tab[i];
  26. cout << endl;
  27.  
  28. for(j = 0; j < N - 1; j++)
  29. for(i = 0; i < N - 1; i++)
  30. if(tab[i] > tab[i + 1])
  31. swap(tab[i], tab[i + 1]);
  32.  
  33.  
  34.  
  35. cout << "Po sortowaniu:";
  36. for(i = 0; i < N; i++)
  37. cout <<" " << tab[i];
  38. cout << endl;
  39. return 0;
  40. }
  41.  
  42.  
  43. //dodawanie systemy:
  44. #include <iostream>
  45.  
  46. using namespace std;
  47.  
  48.  
  49. int main()
  50. {
  51. cout << "Podstawa systemu w ktorym chcesz dodawac?"<< endl;
  52. int p;
  53. cin >> p;
  54. if (p>=2&&p<=9)
  55. {
  56. long long a,b;
  57. cout << "Jakie dwie liczby chcesz dodac?" << endl;
  58. cin >> a >> b;
  59. long long wynik=0;
  60. int mnoznik=1;
  61. int dalej=0;
  62. while (a>0||b>0||dalej>0)
  63. {
  64. int temp=(a%10)+(b%10)+dalej;
  65. if (temp>=p)
  66. {
  67. wynik=wynik+(temp%p)*mnoznik;
  68. dalej=temp/p;
  69. }
  70. else
  71. {
  72. wynik=wynik+temp*mnoznik;
  73. dalej=0;
  74. }
  75. mnoznik=mnoznik*10;
  76. a=a/10;
  77. b=b/10;
  78. }
  79. cout << wynik <<endl;
  80. }
  81. else
  82. cout << "Daj inna podstawe pls"<< endl;
  83. return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement