Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <cmath>
  4. #include <cstdio>
  5. using namespace std;
  6.  
  7.  
  8. //zad 2
  9.  
  10. #define N 3
  11. #define M 3
  12.  
  13. int zad2(int ary[][M]){
  14. int najwieksza=ary[0][0];
  15.  
  16. for(int i=0;i<N;i++){
  17. for(int j=0;j<M;j++){
  18. if(ary[i][j]>najwieksza)
  19. najwieksza = ary[i][j];
  20.  
  21. }
  22.  
  23. }
  24.  
  25. return najwieksza;
  26.  
  27. }
  28.  
  29.  
  30.  
  31. int zad3(int ary[]){
  32. int najwieksza=ary[0];
  33.  
  34. for(int i=0;i<N;i++){
  35. for(int j=0;j<M;j++){
  36. cout<<i<<":"<<j<<" :"<<i*M+j<<endl;
  37.  
  38. if(ary[i*M+j]>najwieksza)
  39. najwieksza = ary[i * M +j];
  40.  
  41. }
  42.  
  43. }
  44.  
  45. return najwieksza;
  46.  
  47. }
  48.  
  49.  
  50.  
  51.  
  52. void zad5(float tab[][M], int n, int m){
  53. float tmp[N][M];
  54. float sum;
  55. int count;
  56. for(int i=0;i < N; i++){
  57. for(int j=0;j<M;j++){
  58. sum = tab[i][j];
  59. count= 1;
  60. if(i>0) sum +=tab[i-1][j], count++;
  61. if(i < n-1) sum +=tab[i+1][j], count++;
  62.  
  63. if(j>0) sum +=tab[i][j-1], count++;
  64. if(j < m-1) sum +=tab[i][j+1], count++;
  65.  
  66. tmp[i][j] = sum /count;
  67.  
  68. }
  69.  
  70. }
  71.  
  72. for(int i=0;i<n;i++){
  73. for(int j=0;j<m;j++){
  74. tab[i][j] = tmp[i][j];
  75. }
  76. }
  77.  
  78. }
  79.  
  80.  
  81. int ToDec(string liczba){
  82. int wielwyr=liczba.size()-1;
  83. int wynik;
  84. for(int i=0;i<liczba.size();i++){
  85. if(liczba[i]=='1'){
  86. wynik=wynik+pow(2,wielwyr-i);
  87. cout<<i<<" "<<pow(2,wielwyr-i)<<endl;
  88. }
  89.  
  90. }
  91.  
  92. return wynik;
  93.  
  94. }
  95.  
  96.  
  97. void zad7(int a, int b){
  98. if(a<0 || b<0){
  99. cout<<"ODP KOMUNIKAT\n";
  100. }else if(b==0){
  101.  
  102. cout<<"NAN\n";
  103.  
  104. }else{
  105.  
  106. cout<<sqrt(a/pow(b,5))<<endl;
  107.  
  108. }
  109.  
  110.  
  111.  
  112.  
  113. }
  114.  
  115.  
  116. int main(){
  117.  
  118. //zad 1
  119.  
  120. /*
  121.  
  122. double suma=0;
  123. int tab[5]={1,3,5,7,8};
  124. for(int i=0;i<5;i++)
  125. {
  126. suma=suma + tab[i];
  127. }
  128.  
  129. suma = suma / 5;
  130. cout<<suma<<endl;
  131. double najblizsza= 41324123;
  132. int element;
  133.  
  134. for(int i=0;i<5;i++){
  135. if(abs(tab[i]-suma) < najblizsza){
  136. najblizsza = abs(tab[i]-suma);
  137. element = i;
  138.  
  139. }
  140.  
  141. }
  142.  
  143. cout<<"Wynik to: "<<tab[element]<<endl;
  144.  
  145. */
  146.  
  147. //int tab[2][3]={2,3,4,2,5,7};
  148. //cout<<zad2(tab)<<endl;;
  149. // int tab3[2*3]={2,3,4,2,5,7};
  150. // cout<<zad3(tab3)<<endl;
  151.  
  152.  
  153.  
  154. /*
  155.  
  156. srand(time(NULL));
  157. float arr[N][M];
  158. for(int i=0;i<N;i++)
  159. {
  160. for(int j=0;j<M;j++){
  161. arr[i][j]=50;
  162. //arr[i][j]=rand() % 100;
  163. }
  164. }
  165.  
  166. for(int i=0;i<N;i++)
  167. {
  168. for(int j=0;j<M;j++){
  169. cout<<arr[i][j]<<" ";
  170. }
  171. }
  172.  
  173.  
  174. zad5(arr,N,M);
  175. cout<<"\n\n";
  176. for(int i=0;i<N;i++)
  177. {
  178. for(int j=0;j<M;j++){
  179. cout<<arr[i][j]<<" ";
  180. }
  181. }
  182.  
  183.  
  184. */
  185.  
  186.  
  187. // string liczba = "1111011";
  188. // cout<<liczba<<endl<<liczba.size()<<endl;
  189. // cout<<ToDec(liczba)<<endl;
  190.  
  191. //ZAD7
  192.  
  193. // int a,b;
  194. // cin>>a>>b;
  195. // zad7(a,b);
  196. /*
  197. int a;
  198. cin>>a;
  199.  
  200. if(a%2==0)
  201. cout<<"1"<<endl;
  202. else
  203. cout<<"0"<<endl;
  204. */
  205.  
  206.  
  207. //zad9
  208. //int n;
  209. //cin>>n;
  210. //cout<< !(n&(n-1))<<endl;
  211.  
  212. //int a,b,A,B;
  213. //scanf("A=%d B=%d",&a, &b);
  214. // printf("%d\t%d\n",a<<b,a>>b);
  215.  
  216. int a,b;
  217. cin>>a>>b;
  218. a ^= b;
  219. b ^= a;
  220. a ^= b;
  221. cout<<"a= "<<a<<" b="<<b<<endl;
  222.  
  223.  
  224. return 0;
  225. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement