You are on page 1of 4

Vježba 28

Z1
#include <iostream>
using namespace std;
#include <ctime>
int main()
{
int n, j, i;
srand(time(0));
cout << "Unesite n: ";
cin >> n;
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
cout << char(rand() % 25 + 65) << "\t";
}
cout << endl;
}
}

Z2
#include <iostream>
using namespace std;
#include <ctime>
int main()
{
int dani, mjesec, brojS;
string chmj;
cout << "Unesite datum (dani):";
cin >> dani;
cout << "Unesite broj mjeseca: ";
cin >> mjesec;
switch (mjesec)
{
case 1:
brojS = 31;
chmj = "Sijecanj";
break;
case 2:
brojS = 28;
chmj = "Veljaca";
break;
case 3:
brojS = 31;
chmj = "Ozujak";
break;
case 4:
brojS = 30;
chmj = "Travanj";
break;
case 5:
brojS = 31;
chmj = "Svibanj";
break;
case 6:
brojS = 30;
chmj = "Lipanj";
break;
case 7:
brojS = 31;
chmj = "Srpanj";
break;
case 8:
brojS = 31;
chmj = "Kolovoz";
break;
case 9:
brojS = 30;
chmj = "Rujan";
break;
case 10:
brojS = 31;
chmj = "Listopad";
break;
case 11:
brojS = 30;
chmj = "Studeni";
break;
case 12:
brojS = 31;
chmj = "Prosinac";
break;
default:
break;
}
cout << "Trenutni mjesec:" << chmj<<endl;
cout << "Broj dana do kraja mjeseca: " << brojS - dani;
}

Z3
#include <iostream>
using namespace std;
#include <ctime>
int main()
{
srand(time(0));
int a, b, i;
a = rand() % 100;
cout << a;
do
{
cout << "Pogodite broj (1-100): ";
cin >> b;
if (b > a)
{
cout << "Broj je manji." << endl;
}
else if (a > b)
{
cout << "Broj je veci." << endl;
}
i++;
} while (a != b);
cout << "Cestitamo, pogodili ste broj!" << endl;
cout << "Broj pokusaja: " << i;
}

Z4
#include <iostream>
#include <ctime>
using namespace std;
int main()
{
int a, b;
int i = 1, ponavljanja;
b = rand() % 100;
cout << "Unesite broj igraca: ";
cin >> ponavljanja;
do
{
int pokusaji = 1;
cout << "Na redu je " << i << ". igrac. " << endl;
cout << "Pogodite broj. (1-100): ";
cin >> a;
while (a != b)
{
if (a > b)
{
cout << "Broj je manji. " << endl;
}
else
cout << "Broj je veci. " << endl;
cout << "Pokusaj opet: ";
cin >> a;
pokusaji++;
}
cout << "Cestitamo pogodili ste broj! " << endl;
cout << "Broj pokusaja " << i << ". igraca je " << pokusaji << endl;
i++;
} while (i <= ponavljanja);
}

You might also like