This commit is contained in:
parent
dc1583cd8c
commit
4c003c5ebd
1 changed files with 18 additions and 47 deletions
65
main.cpp
65
main.cpp
|
@ -1,58 +1,29 @@
|
|||
#include <iostream>
|
||||
#include <cmath>
|
||||
using namespace std;
|
||||
|
||||
bool prime(int x)
|
||||
{
|
||||
if (x < 2) return false;
|
||||
for (int i=2; i<= sqrt(x); i++) {
|
||||
if ((x%i) == 0) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int zad1(int n, int i, int x) {
|
||||
|
||||
cout << "podaj n = ";
|
||||
cin >> n;
|
||||
|
||||
for(int x=1; x<=n; x++)
|
||||
{
|
||||
if (prime(x) == true) {
|
||||
cout << x << " ";
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int zad2(int n) {
|
||||
cout << "Podaj n = ";
|
||||
cin >> n;
|
||||
|
||||
if (n<0) {
|
||||
cout << "n nie moze byc mniejsze od 0";
|
||||
}
|
||||
else {
|
||||
int i = 1;
|
||||
while (i<=n)
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
int n,i,x;
|
||||
string que;
|
||||
int i,n;
|
||||
float suma;
|
||||
int f[100], f0, f1;
|
||||
float zl;
|
||||
|
||||
cout << "zadanie? = (zad1, zad2, zad3)";
|
||||
cin >> que;
|
||||
|
||||
if (que == "zad1") {
|
||||
zad1(n,i,x);
|
||||
}
|
||||
if (que == "zad2") {
|
||||
zad2(n);
|
||||
cout << "N = ";
|
||||
cin >> n;
|
||||
f0 = 0;
|
||||
f1 = 1;
|
||||
cout << f0 << " " << f1 << " ";
|
||||
for(i = 2;i<=n;i++) {
|
||||
suma = f0 + f1;
|
||||
cout << suma << " ";
|
||||
f0 = f1;
|
||||
f1 = suma;
|
||||
}
|
||||
|
||||
cout << endl;
|
||||
zl = suma/f0;
|
||||
|
||||
cout << "\nZlota liczba = " << zl << endl;
|
||||
|
||||
system("pause");
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Reference in a new issue