Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 3.
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int wygeneruj(int *tab, int n, int pom)
- {
- if(n>0)
- {
- if(n==pom)
- {
- tab[pom-n]=(rand()%10)+1;
- return wygeneruj(tab,n-1,pom);
- }
- else
- {
- tab[pom-n]=(rand()%27)-14;
- return wygeneruj(tab,n-1,pom);
- }
- }
- return 0;
- }
- void wyswietl(int *tab, int n)
- {
- /*for(int i=0; i<n; i++)
- {
- cout<<tab[i]<<" ";
- }
- cout<<endl;*/
- if(n>0)
- {
- wyswietl(tab,n-1);
- cout<<tab[n-1]<<" ";
- }
- }
- void wyswietlt(int *tab, int n)
- {
- int pom=0;
- for(int i=0; i<n; i++)
- {
- if(tab[i]%(-7)==0)
- {
- cout<<"Tablica dla indexu "<<i+1<<" jest podzielna przez -7: "<<tab[i]<<endl;
- pom++;
- }
- }
- if(pom==0)
- {
- cout<<"Brak"<<endl;
- }
- pom=0;
- }
- int main()
- {
- srand(time(NULL));
- int n=10,*tab;
- tab=new int[n];
- cout<<wygeneruj(tab,n,n)<<endl;
- cout<<"Tablica:"<<endl;
- wyswietl(tab,n);
- cout<<endl;
- cout<<"Liczby podzielne przez -7"<<endl;
- wyswietlt(tab,n);
- return 0;
- }
- 6.
- #include <iostream>
- #include <math.h>
- #include <cstdlib>
- using namespace std;
- float oblicz(float x, float a, float n, float eps=0.0001)
- {
- if(n==0)
- {
- return oblicz(x,a,n+2);
- }
- else
- {
- if(a>eps) return a+oblicz(x,(-1)*a*(x*x)/((n+2)*(n+1)),n+2);
- return 0;
- }
- }
- int main()
- {
- float x=0.785398,a=1;
- x=x*180/M_PI;
- cout<<x<<endl;
- cout<<oblicz(x,x,0)<<endl;
- cout<<cos(x);
- return 0;
- }
- 11.
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- #include <iomanip>
- using namespace std;
- void wypelnijzerami(int n, float **tab)
- {
- for(int i=0; i<n; i++)
- {
- for(int j=0; j<n; j++)
- {
- tab[i][j]=0;
- }
- }
- }
- void wyswietl1(int n, float **tab)
- {
- for(int i=0; i<n; i++)
- {
- for(int j=0; j<n; j++)
- {
- cout<<tab[i][j]<<" ";
- }
- cout<<endl;
- }
- }
- void wyswietl(int x,int y, float **tab)
- {
- if(y>=0)
- {
- cout<<tab[x][y-1]<<" ";
- wyswietl(x-1,y,tab);
- }
- if(x>=0)
- {
- cout<<tab[x-1][y]<<" ";
- wyswietl(x,y-1,tab);
- }
- }
- float przekatna(int x, int y, float **tab)
- {
- cout<<setprecision(2)<<fixed;
- if(x>=0 || y>=0)
- {
- if((x-1)>=0)
- {
- tab[x-1][y]=0.0+7.0*rand()/RAND_MAX;
- }
- if((y-1)>=0)
- {
- tab[x][y-1]=1.0+7.0*rand()/RAND_MAX;
- }
- tab[x][y]=1.0+7.0*rand()/RAND_MAX;
- return przekatna(x-1,y-1,tab);
- }
- else return 0;
- }
- int main()
- {
- srand(time(NULL));
- int n=5;
- float **macierz;
- macierz=new float*[n];
- for(int i=0; i<n; i++)
- {
- macierz[i]=new float[n];
- }
- wypelnijzerami(n,macierz);
- przekatna(n-1,n-1,macierz);
- wyswietl1(n,macierz);
- //cout<<endl;
- //wyswietl(n,n,macierz);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement