Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. 3.
  2. #include <iostream>
  3. #include <cstdlib>
  4. #include <ctime>
  5.  
  6. using namespace std;
  7.  
  8. int wygeneruj(int *tab, int n, int pom)
  9. {
  10. if(n>0)
  11. {
  12. if(n==pom)
  13. {
  14. tab[pom-n]=(rand()%10)+1;
  15. return wygeneruj(tab,n-1,pom);
  16. }
  17. else
  18. {
  19. tab[pom-n]=(rand()%27)-14;
  20. return wygeneruj(tab,n-1,pom);
  21. }
  22. }
  23. return 0;
  24. }
  25.  
  26. void wyswietl(int *tab, int n)
  27. {
  28. /*for(int i=0; i<n; i++)
  29. {
  30. cout<<tab[i]<<" ";
  31. }
  32. cout<<endl;*/
  33.  
  34. if(n>0)
  35. {
  36. wyswietl(tab,n-1);
  37. cout<<tab[n-1]<<" ";
  38. }
  39.  
  40. }
  41.  
  42. void wyswietlt(int *tab, int n)
  43. {
  44. int pom=0;
  45. for(int i=0; i<n; i++)
  46. {
  47. if(tab[i]%(-7)==0)
  48. {
  49. cout<<"Tablica dla indexu "<<i+1<<" jest podzielna przez -7: "<<tab[i]<<endl;
  50. pom++;
  51. }
  52. }
  53. if(pom==0)
  54. {
  55. cout<<"Brak"<<endl;
  56. }
  57. pom=0;
  58. }
  59.  
  60. int main()
  61. {
  62. srand(time(NULL));
  63. int n=10,*tab;
  64. tab=new int[n];
  65.  
  66. cout<<wygeneruj(tab,n,n)<<endl;
  67. cout<<"Tablica:"<<endl;
  68. wyswietl(tab,n);
  69. cout<<endl;
  70. cout<<"Liczby podzielne przez -7"<<endl;
  71. wyswietlt(tab,n);
  72. return 0;
  73. }
  74. 6.
  75. #include <iostream>
  76. #include <math.h>
  77. #include <cstdlib>
  78.  
  79. using namespace std;
  80.  
  81. float oblicz(float x, float a, float n, float eps=0.0001)
  82. {
  83.  
  84. if(n==0)
  85. {
  86.  
  87. return oblicz(x,a,n+2);
  88. }
  89. else
  90. {
  91. if(a>eps) return a+oblicz(x,(-1)*a*(x*x)/((n+2)*(n+1)),n+2);
  92. return 0;
  93. }
  94.  
  95.  
  96. }
  97.  
  98. int main()
  99. {
  100. float x=0.785398,a=1;
  101.  
  102. x=x*180/M_PI;
  103.  
  104. cout<<x<<endl;
  105.  
  106. cout<<oblicz(x,x,0)<<endl;
  107. cout<<cos(x);
  108.  
  109. return 0;
  110. }
  111. 11.
  112. #include <iostream>
  113. #include <cstdlib>
  114. #include <ctime>
  115. #include <iomanip>
  116.  
  117. using namespace std;
  118.  
  119. void wypelnijzerami(int n, float **tab)
  120. {
  121. for(int i=0; i<n; i++)
  122. {
  123. for(int j=0; j<n; j++)
  124. {
  125. tab[i][j]=0;
  126. }
  127. }
  128. }
  129.  
  130. void wyswietl1(int n, float **tab)
  131. {
  132. for(int i=0; i<n; i++)
  133. {
  134. for(int j=0; j<n; j++)
  135. {
  136. cout<<tab[i][j]<<" ";
  137. }
  138. cout<<endl;
  139. }
  140. }
  141.  
  142. void wyswietl(int x,int y, float **tab)
  143. {
  144.  
  145.  
  146. if(y>=0)
  147. {
  148. cout<<tab[x][y-1]<<" ";
  149. wyswietl(x-1,y,tab);
  150.  
  151.  
  152. }
  153.  
  154. if(x>=0)
  155. {
  156. cout<<tab[x-1][y]<<" ";
  157. wyswietl(x,y-1,tab);
  158.  
  159. }
  160.  
  161.  
  162.  
  163. }
  164. float przekatna(int x, int y, float **tab)
  165. {
  166. cout<<setprecision(2)<<fixed;
  167. if(x>=0 || y>=0)
  168. {
  169. if((x-1)>=0)
  170. {
  171. tab[x-1][y]=0.0+7.0*rand()/RAND_MAX;
  172. }
  173.  
  174. if((y-1)>=0)
  175. {
  176. tab[x][y-1]=1.0+7.0*rand()/RAND_MAX;
  177. }
  178.  
  179. tab[x][y]=1.0+7.0*rand()/RAND_MAX;
  180. return przekatna(x-1,y-1,tab);
  181. }
  182. else return 0;
  183.  
  184. }
  185.  
  186.  
  187.  
  188.  
  189.  
  190. int main()
  191. {
  192. srand(time(NULL));
  193. int n=5;
  194. float **macierz;
  195. macierz=new float*[n];
  196. for(int i=0; i<n; i++)
  197. {
  198. macierz[i]=new float[n];
  199. }
  200.  
  201. wypelnijzerami(n,macierz);
  202. przekatna(n-1,n-1,macierz);
  203. wyswietl1(n,macierz);
  204. //cout<<endl;
  205. //wyswietl(n,n,macierz);
  206.  
  207. return 0;
  208. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement