Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //zad 1
- /*
- #include <iostream>
- using namespace std;
- int add(int a, int b)
- {
- return a+b;
- }
- int sub(int a, int b)
- {
- return a-b;
- }
- int main()
- {
- int a,b;
- cin>>a>>b;
- int(*fun)(int,int);
- fun=add;
- cout<<fun(a,b)<<endl;
- fun=sub;
- cout<<fun(a,b)<<endl;
- return 0;
- }
- */
- //zad 2
- /*
- #include <iostream>
- using namespace std;
- float add(float a,float b)
- {
- return a+b;
- }
- float sub(float a,float b)
- {
- return a-b;
- }
- float mul(float a,float b)
- {
- return a*b;
- }
- float div(float a,float b)
- {
- return a/b;
- }
- int main()
- {
- unsigned int o;
- float a,b;
- float (*fun[4])(float,float);
- fun[0]=add;
- fun[1]=sub;
- fun[2]=mul;
- fun[3]=div;
- cin>>a>>b>>o;
- cout<<fun[o](a,b)<<endl;
- return 0;
- }
- */
- //zad 3
- /*
- #include <iostream>
- using namespace std;
- int min(int a,int b)
- {
- return a<b ? a:b;
- }
- int max(int a,int b)
- {
- return a>b ? a:b;
- }
- int f(int arr[],int n, int (*fun)(int,int))
- {
- int tmp=arr[0];
- for(int i=0;i<n;++i)
- tmp=fun(tmp,arr[i]);
- return tmp;
- }
- int main()
- {
- int arr[]={1,2,3,4,5,6,7,8,0,15,12,7,6,22,11};
- int n=15;
- cout<<f(arr,n,min)<<endl;
- cout<<f(arr,n,max)<<endl;
- return 0;
- }
- */
- //zad 4
- /*
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- int min(const void *a, const void *b)
- {
- float *ptr_a=(float *)a;
- float *ptr_b=(float *)b;
- float value_a= *ptr_a;
- float value_b=*ptr_b;
- //value_a=*(float*)a;value_b=*(float *)b;
- if(value_a<value_b) return -1;
- else if(value_a==value_b) return 0;
- else return 1;
- }
- int max(const void *a, const void *b)
- {
- return *(int*)b - *(int *)a;
- }
- int main()
- {
- float arr1[]={1.f,2.f,3.f,5.f,13.f,0.f,12.f,13.f,5.f,7.f};
- int arr2[]={1,2,3,4,5,6,7,8,0,15,12,7,6,22,11};
- qsort(arr1,10,sizeof(arr1[0]),min);
- for(int i=0;i<10;++i)
- cout<<arr1[i]<<" ";
- cout<<endl;
- qsort(arr2,15,sizeof(arr2[0]),max);
- for(int i=0;i<15;++i)
- cout<<arr2[i]<<" ";
- cout<<endl;
- return 0;
- }
- */
- //zad 5
- /*
- #include <iostream>
- #include <cstdlib>
- #include <cstring>
- using namespace std;
- int compare(const void *p1, const void *p2)
- {
- return -strcmp((char*)p1, (char*)p2);
- }
- int main()
- {
- char arr[5][100]={"tygrys syberyjski","krokodyl nilowy","panda wielka","tygrys azjatycki","chomik europejski"};
- qsort(arr,5,100,compare);
- for(int i=0;i<5;++i) cout<<arr[i]<<endl;
- return 0;
- }
- */
- //zad 6
- /*
- #include <cstdio>
- #include <string>
- using namespace std;
- int main()
- {
- char str[11]={0};
- scanf("%10s",str);
- int value=stoi(str)+10;
- printf("%d\n",value);
- return 0;
- }
- */
- //zad 7
- /*
- #include <iostream>
- using namespace std;
- int binary_search(int *arr, int l, int r, int x)
- {
- if(r>=1)
- { int mid=l+(r-l)/2;
- if(arr[mid]==x) return mid;
- else if(arr[mid]>x)return binary_search(arr,l, mid-1,x);
- else return binary_search(arr,mid+1,r,x);
- }
- return -1;
- }
- int main()
- {
- int arr[]={1,2,3,4,10,22,23,42};
- int x=4;
- int n=sizeof(arr)/sizeof(arr[0]);
- int result=binary_search(arr,0,n-1,x);
- cout<<((result==-1)? "Brak": to_string(result)) <<endl;
- return 0;
- }
- */
- //zad 8
- /*
- #include <iostream>
- using namespace std;
- void f(int *matrix, int N)
- {
- for(int i=0;i<N;++i) for(int j=0;j<N;++j) matrix[i*N+j]=(i+1)*(j+1);
- }
- int main()
- {
- int N=10;
- int *arr=new int[N*N];
- f(arr,N);
- for(int i=0;i<N;++i){
- for(int j=0;j<N;++j)
- cout<<arr[i*N+j]<<" ";
- cout<<endl;
- }
- delete [] arr;
- return 0;
- }
- */
- //zad 9
- /*
- #include <iostream>
- using namespace std;
- void f(float *arr, int n, int m, float **result)
- {
- for(int i=0;i<n;++i)
- for(int j=0;j<m;++j)
- if(i==0 || j==0 ||i==n-1 || j==m-1) result[i][j]=0.f;
- else result[i][j]=arr[i*m+j];
- }
- int main()
- {
- int n=3, m=5;
- float **result=nullptr;
- float arr[15]={1.f,1.f,1.f,1.f,1.f,1.f,1.f,1.f,1.f,1.f,1.f,1.f,1.f,1.f,1.f};
- result=new float*[n];
- for(int i=0;i<n;++i)
- result[i]=new float[m];
- f(arr,n,m,result);
- for(int i=0;i<n;++i)
- {
- for(int j=0;j<m;++j)
- cout<<result[i][j]<<" ";
- cout<<endl;
- }
- delete[] result;
- return 0;
- }
- */
- //zad 10
- /*
- #include <iostream>
- #include <numeric> //iota, accumulate,inner_product
- #include <algorithm> //random_shuffle
- using namespace std;
- int main()
- {
- int n,x,init=0;
- cin>>n>>x;
- int *t1=nullptr, *t2=nullptr;
- t1=new int[n];
- t2=new int[n];
- iota(t1,t1+n,x);
- iota(t2,t2+n,x);
- random_shuffle(t1,t1+n);
- random_shuffle(t2,t2+n);
- for(int i=0;i<n;++i) cout<<t1[i]<<" "; cout<<endl;
- for(int i=0;i<n;++i) cout<<t2[i]<<" "; cout<<endl;
- cout<<accumulate(t1,t1+n,init)<<endl;
- cout<<inner_product(t1,t1+n,t2,init)<<endl;
- delete[] t1;
- delete[] t2;
- return 0;
- }
- */
- //zad 11
- /*
- #include <iostream>
- using namespace std;
- #define MAX_SIZE 100
- int main()
- {
- char str[MAX_SIZE], reverse[MAX_SIZE];
- char *s=str;
- char *r=reverse;
- cin>>str;
- int len=0;
- while(*(s++)) len++;
- s--;
- while(len>=0)
- {
- *(r++)=*(--s);
- len--;
- }
- *r='\0';
- cout<<"Original: "<<str<<endl;
- cout<<"Reverse: "<<reverse<<endl;
- return 0;
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement