Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <time.h>
- #include <math.h>
- #include <stdlib.h>
- using namespace std;
- int main()
- {
- /* --- ZADANIE 1A --- */
- cout << "ZADANIE 1A" << endl << endl;
- int a, b = 0;
- cout << "Podaj 2 liczby calkowite: ";
- cin >> a >> b;
- switch(a)
- {
- case 12:
- cout << "Podano liczbe 12, a druga liczba to: " << b;
- break;
- case -12:
- cout << "Kwadrat drugiej liczby: " << b * b;
- break;
- case 15:
- cout << "Druga liczba podzielona przez 5: " << (float)b / 5.0;
- break;
- case 22:
- {
- error:
- if(b < 0)
- {
- cout << "Podaj ponownie 2 liczbe (taka aby byla >= 0): ";
- cin >> b;
- goto error;
- }
- cout << "Pierwiastek z drugiej liczby: " << sqrt(b);
- break;
- }
- case -24:
- cout << "Srednia z obu liczb: " << (float)(a + b) / 2.0;
- break;
- default:
- cout << "nieprawidlowy wybor";
- }
- cout << endl;
- /* --- ZADANIE 1B --- */
- cout << endl << "ZADANIE 1B" << endl << endl;
- for(int i = 10; i <= 21; i++)
- {
- cout.width( 4 );
- cout << i;
- }
- cout << endl << endl;
- for(int i = 45; i >= -15; i-=5)
- {
- cout.width( 4 );
- cout << i;
- }
- cout << endl << endl;
- for(int i = 1; i <= 9; i++)
- {
- for(int a = 1; a <= 11; a++)
- {
- cout.width( 4 );
- cout << a * i;
- }
- cout << endl;
- }
- cout << endl << endl;
- for(int i = 9; i >= 2; i--)
- {
- for(int a = 7; a >= 2; a--)
- {
- cout.width( 4 );
- cout << a * i;
- }
- cout << endl;
- }
- /* --- ZADANIE 2A --- */
- cout << endl << "ZADANIE 2A" << endl << endl;
- double A;
- cout << "Podaj liczbe A (double): ";
- cin >> A;
- PK_1:
- if(A > 0)
- {
- A /= 10;
- if(A < 8)
- {
- A += 12;
- PK_3:
- if(A < 50)
- {
- cout << "Liczba A: " << A << endl;
- goto the_end;
- }
- else
- {
- goto PK_1;
- }
- }
- else
- {
- A -= 20;
- goto PK_1;
- }
- }
- else
- {
- PK_2:
- A += 10;
- if(A < 20)
- {
- goto PK_2;
- }
- else
- {
- A /= 3;
- goto PK_3;
- }
- }
- the_end:
- // Wyjscie z programu po wyswietleniu liczy A
- // return 0;
- /* --- ZADANIE 2B --- */
- cout << endl << "ZADANIE 2B" << endl << endl;
- srand(time(NULL));
- for(int i = 0; i < 10; i++)
- {
- cout << rand() % 10 + 1 << " ";
- }
- cout << endl << endl;
- for(int i = 0; i < 10; i++)
- {
- cout << rand() % 501 - 200 << " ";
- }
- cout << endl << endl;
- for(int i = 0; i < 10; i++)
- {
- comeback:
- int a = rand() % 101 - 60;
- if (a % 4 == 0)
- cout << a << " ";
- else
- goto comeback;
- }
- cout << endl << endl;
- for(int i = 0; i < 10; i++)
- {
- float f = (rand() % 301) / 10.0;
- f -= 15.0;
- cout << f << " ";
- }
- cout << endl << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement