Skip to content

Instantly share code, notes, and snippets.

@pagenoare
Created November 27, 2012 17:27
Show Gist options
  • Save pagenoare/4155693 to your computer and use it in GitHub Desktop.
Save pagenoare/4155693 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <math.h>
using namespace std;
void choinka(int n, int add = 0)
{
n *= 2;
for(int i = 1; i <= n; i++)
{
for(int k = ((n - i) / 2) + add; k >= 0; k--)
{
cout << " ";
}
for(int j = 1; j <= i; j++)
{
if(i % 2 != 0)
{
cout << "*";
}
}
if(i % 2 == 0)
cout << endl;
}
}
int main()
{
int act, z, x, poz, pien_poz;
int a, b, c, delta;
int n = 1, y = 1;
cout << "==== MENU ====" << endl;
cout << "1. Choinka. " << endl;
cout << "2. Wpisuj liczbe dopoki i != 0. " << endl;
cout << "3. Trojmian. " << endl;
cout << "4. Choinka 2" << endl;
cout << "5. Choinka 3" << endl << endl;
cout << "Akcja: ";
cin >> act;
switch(act) {
case 1:
cout << "Wysokosc choinki: ";
cin >> n;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= i; j++)
{
cout << "*";
}
cout << endl;
}
z = 1;
while(z <= n)
{
x = 1;
while(x <= z)
{
cout << "*";
x++;
}
cout << endl;
z++;
}
break;
case 2:
for(int i = 1; n != 0; i++)
{
cin >> n;
}
cout << "Zero!" << endl;;
while(y != 0)
{
cin >> y;
}
cout << "Koniec!";
break;
case 3:
cout << "Podaj A: ";
cin >> a;
cout << "Podaj B: ";
cin >> b;
cout << "Podaj C: ";
cin >> c;
delta = pow(b, 2) - 4*a*c;
if(delta < 0)
{
cout << "DELTA JEST UJEMNA!" << endl;
break;
}
if(delta == 0)
{
cout << "x = " << -b / 2 * a;
} else {
cout << "x1 = " << (-b + sqrt(delta)) / 2 * a << endl;
cout << "x2 = " << (-b - sqrt(delta)) / 2 * a << endl;
}
break;
case 4:
cout << "Wysokosc choinki: ";
cin >> n;
choinka(n);
break;
case 5:
cout << "Ilosc poziomow choinki: ";
cin >> poz;
for(int i = 0; i < poz; i++)
{
choinka(2 + i, poz - i);
}
pien_poz = (poz * 2) - 1;
for(int i = 0; i < poz; i++)
{
for(int j = 0; j < pien_poz; j++)
{
cout << " ";
}
cout << "*";
cout << endl;
}
break;
}
getchar();
getchar();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment