Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- #include <iomanip>
- #include <cstring>
- using namespace std;
- struct kursant
- {
- char imie [10];
- int punkty [5];
- };
- int suma(kursant uczestnik,int n,int sumaPkt)
- {
- if(n<0)return sumaPkt;
- sumaPkt=sumaPkt + uczestnik.punkty[n];
- return suma(uczestnik,n-1,sumaPkt);
- }
- int main()
- {
- srand(time(NULL));
- char imiona [8][10] = {
- "Agnieszka",
- "Piotr",
- "Michal",
- "Andrzej",
- "Kasia",
- "Ania",
- "Tomek",
- "Bozena"
- };
- kursant uczestnicy [15];
- for( int i = 0 ; i < 15 ; i++)
- {
- int los=rand()%8;
- for (int j = 0 ; imiona[los][j]!='\0' ; j++)
- {
- // uczestnicy[i].imie[j]=imiona[los][j];
- strcpy(uczestnicy[i].imie,imiona[los]);
- }
- }
- for( int i = 0 ; i < 15 ; i++)
- {
- for (int j = 0; j < 5 ; j++)
- {
- uczestnicy[i].punkty[j]=rand()%11;
- //cout << uczestnicy[i].punkty[j] << " ";
- }
- }
- cout <<"imiona uczestnikow:" << endl;
- for( int i = 0 ; i < 15 ; i++)
- {
- for (int j = 0 ; uczestnicy[i].imie[j]!='\0' ; j++)
- {
- cout << uczestnicy[i].imie[j];
- }
- cout << endl;
- }
- cout << endl;
- cout << "punkty uczestników:" << endl;
- for( int i = 0 ; i < 15 ; i++)
- {
- for (int j = 0 ; j < 5; j++)
- {
- cout << setw (2) << uczestnicy[i].punkty[j] << " ";
- }
- cout << endl;
- }
- cout << endl;
- cout << "suma: " << endl;
- for( int i = 0 ; i < 15 ; i++)
- {
- cout << suma(uczestnicy[i],5,0) << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement