Advertisement
Guest User

Untitled

a guest
Dec 16th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <time.h>
  4.  
  5. using namespace std;
  6.  
  7. int random(int min, int max)
  8. {
  9. static bool first = true;
  10. if (first)
  11. {
  12. srand( time(NULL) );
  13. first = false;
  14. }
  15. return min + rand() % (( max + 1 ) - min);
  16. }
  17.  
  18. int main()
  19. {
  20. int m,n;
  21. int naj = -100;
  22. int ii=0,jj=0;
  23.  
  24. cout<<"Program szuka najwiekszej liczby w tablicy dwuwymiarowej !"<<endl<<endl;
  25.  
  26. cout<<"Podaj m: ";
  27. cin>>m;
  28. cout<<endl;
  29. cout<<"Podaj n: ";
  30. cin>>n;
  31. cout<<endl;
  32.  
  33. //DEKLAROWANIE TABLICY
  34. int **tab = new int *[m];
  35. for(int i =0; i < n; i++)
  36. {
  37. tab[i] = new int [n];
  38. }
  39.  
  40. //WYPELNIANIE
  41. for(int i = 0; i < m; i++)
  42. {
  43. for(int j = 0; j < n; j++)
  44. {
  45. tab[i][j] = random(0,200);
  46. }
  47. }
  48.  
  49.  
  50. cout<<endl;
  51. cout<<"Wygenerowana tablica:"<<endl;
  52. //WYPISANIE TABLICY
  53. for(int i = 0; i < m; i++)
  54. {
  55. for(int j = 0; j < n; j++)
  56. {
  57. cout<<tab[i][j]<<" ";
  58. }
  59.  
  60. cout<<endl;
  61. }
  62.  
  63. //SZUKANIE WARTOSCI NAJWIESKZEJ
  64. for(int i = 0; i < m; i++)
  65. {
  66. for(int j = 0; j < n; j++)
  67. {
  68. if(tab[i][j] > naj)
  69. {
  70. naj = tab[i][j];
  71. ii = i;
  72. jj = j;
  73. }
  74. }
  75. }
  76.  
  77. cout<<"Wyniki: "<<endl;
  78. cout<<"Najwieksza liczba: "<<naj;
  79. cout<<endl<<"Pozycja wiersz: "<<ii<< " kolumna: "<<jj;
  80.  
  81.  
  82. return 0;
  83. }
  84. ---------
  85. #include <iostream>
  86. #include <cstdlib>
  87. #include <time.h>
  88. #include <string>
  89.  
  90. using namespace std;
  91.  
  92. bool isCyfra(string napis)
  93. {
  94. for(int i = 0; i < napis.length(); i++)
  95. {
  96. if(napis.at(i) >= '0' && napis.at(i) <= '9')
  97. return true;
  98. }
  99.  
  100. return false;
  101. }
  102.  
  103. int main()
  104. {
  105. int n;
  106. cout<<"Program wczytuje n napisow i rodziela !";
  107. cout<<endl;
  108.  
  109. cout<<"Podaj n: ";
  110. cin>>n;
  111. cout<<endl;
  112.  
  113. int i1=0,i2=0,i3=0;
  114.  
  115. //DEKLAROWANIE TABLICY
  116. string **tab = new string *[3];
  117. for(int i =0; i < 3; i++)
  118. {
  119. tab[i] = new string [n];
  120. }
  121.  
  122.  
  123. //WPISYWANIE DO TABLICY
  124. for(int i = 0; i < n; i++)
  125. {
  126. string tmp;
  127. cin>>tmp;
  128.  
  129. if(tmp.length() > 10)
  130. {
  131. tab[0][i1] = tmp;
  132. i1++;
  133. }
  134.  
  135. if(tmp.at(0) >= 'A' && tmp.at(0) <= 'Z')
  136. {
  137. tab[1][i2] = tmp;
  138. i2++;
  139. }
  140.  
  141. if(isCyfra(tmp))
  142. {
  143. tab[2][i3] = tmp;
  144. i3++;
  145. }
  146. }
  147.  
  148. cout<<"Wyniki: "<<endl;
  149.  
  150. for(int i = 0; i < 3; i++)
  151. {
  152. for(int j = 0; j < n; j++)
  153. {
  154.  
  155. cout<<tab[i][j]<<" ";
  156.  
  157. }
  158. cout<<endl;
  159. }
  160.  
  161.  
  162. return 0;
  163. }
  164.  
  165. -----------
  166. #include <iostream>
  167.  
  168. using namespace std;
  169.  
  170. int horner(int wsp[],int st, int x)
  171. {
  172. if(st==0)
  173. return wsp[0];
  174.  
  175. return x*horner(wsp,st-1,x)+wsp[st];
  176. }
  177.  
  178. int main()
  179. {
  180. int *wspolczynniki;
  181. int stopien, argument;
  182.  
  183. cout<<"Program oblicza wielomian n-stopnia !"<<endl<<endl;
  184.  
  185. cout<<"Podaj stopien wielomianu: ";
  186. cin>>stopien;
  187.  
  188. wspolczynniki = new int [stopien+1];
  189.  
  190. for(int i=0;i<=stopien;i++)
  191. {
  192. cout<<"Podaj wspolczynnik stojacy przy potêdze "<<stopien-i<<": ";
  193. cin>>wspolczynniki[i];
  194. }
  195.  
  196. cout<<"Podaj argument X: ";
  197. cin>>argument;
  198.  
  199. cout<<"W( "<<argument<<" ) = "<<horner(wspolczynniki,stopien,argument)<<endl;
  200.  
  201. return 0;
  202. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement