Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <time.h> // srand() i rand()
- using namespace std;
- void pokaz(float tab[],const int n){
- cout<< "wyswietlamy wynik:\n";
- for(int i=0;i<n;i++){
- cout<<tab[i]<<" ";
- }cout<<endl;
- }
- int dodaj(float tab[],const int n){
- int a=0;
- int b=0;
- cout<<"wyswietlamy losowe liczby i dodajemy je:\n";
- for(int i=0;i<n;i++){
- a=rand()%10+1;
- b=rand()%20+1;
- cout << a <<" "<<b<<endl;
- tab[i]=a+b;
- }
- return* tab;
- }
- int podziel(float tab[],const int n){
- cout << "dzielimy dodane przez siebie liczby:\n";
- for(int i=0;i<n;i++){
- tab[i]/=2;
- }
- return* tab;
- }
- int suma(float tab[],float& wynik,const int n){
- // uzylem typ float ze wzgledu na dokladnosc obliczeniowa
- cout<<"Sumujemy wszystkie liczby i zapisaujemy wynik:\n";
- for(int i=0;i<n;i++){
- wynik+=tab[i];
- }
- return wynik;
- }
- int main(){
- srand(time(NULL));
- int n=10;
- float tab[n];
- float wynik = 0;
- dodaj(tab,n);
- pokaz(tab,n);
- cout<<endl;
- podziel(tab,n);
- pokaz(tab,n);
- cout<<endl;
- suma(tab,wynik,n);
- cout << wynik;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement