Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <bits/stdc++.h>
- using namespace std;
- bool jeLiProst(int broj)
- {
- if (broj == 0 || broj == 1)
- return false;
- for (int i = 2; i <= broj / 2; ++i)
- if (broj % i == 0)
- return false;
- return true;
- }
- int brojZnamenaka(int broj)
- {
- int brojac = 0;
- while(broj!=0)
- {
- brojac++;
- broj/=10;
- }
- return brojac;
- }
- bool zbrojZnamenaka(int broj, int n)
- {
- int zbroj1 = 0, zbroj2 = 0;
- int znam = brojZnamenaka(broj);
- if(znam < n)
- return false;
- for(int i=0;i<n;i++)
- {
- zbroj1+=broj%10;
- broj/=10;
- }
- for(int i=0;i<znam;i++)
- {
- zbroj2+=broj%10;
- broj/=10;
- }
- if(zbroj1==zbroj2)
- return true;
- return false;
- }
- void zbrojZnamenakaUpetlji()
- {
- int unos, N;
- cout<<"Unos: "; cin>>unos;
- cout<<"N: "; cin>>N;
- while(true)
- {
- if(zbrojZnamenaka(unos,N) == 1)
- break;
- else
- {
- cout<<"Unos: "; cin>>unos;
- cout<<"N: "; cin>>N;
- }
- }
- }
- bool usporediZnamenke(int broj1, int broj2)
- {
- bool prva[10] ={0}, druga[10]={0};
- while(broj1)
- {
- prva[broj1%10]=1;
- broj1/=10;
- }
- while(broj2)
- {
- druga[broj2%10]=1;
- broj2/=10;
- }
- for (int i=0; i<10; i++){
- cout<<prva[i]<<" ";
- }
- cout<<endl;
- for (int i=0; i<10; i++)
- cout<<druga[i]<<" ";
- cout<<endl;
- for (int i=0; i<10; i++){
- if (prva[i]!=druga[i])
- return false;
- }
- return false;
- }
- int obrnuti(int broj)
- {
- int obrnuti=0;
- int znam = brojZnamenaka(broj);
- for(int i=0;i<znam;i++)
- {
- obrnuti*=10;
- obrnuti+=broj%10;
- broj/=10;
- }
- return obrnuti;
- }
- int ukupnoVrijeme(int h, int m, int s)
- {
- return h*3600 + m*60 + s;
- }
- float sekundeuSate(int s)
- {
- return s/3600.0;
- }
- int sekundeuMinute(int s)
- {
- if(s/60 > 60)
- return s/60 - 60;
- return s/60;
- }
- void ispisiNputa(int n)
- {
- static int broj = 0;
- cout<<broj<<endl;
- broj++;
- if(broj == n+1)
- return;
- ispisiNputa(n);
- }
- int main()
- {
- //cout << jeLiProst(4) << endl;
- //cout << brojZnamenaka(4323) << endl;
- //cout << zbrojZnamenaka(1214,1) << endl;
- //zbrojZnamenakaUpetlji();
- //cout<<usporediZnamenke(1221, 12119)<<endl;
- //cout<<obrnuti(4003)<<endl;
- //cout<<ukupnoVrijeme(2,35,21)<<endl;
- //cout<<sekundeuSate(12336)<<endl;
- //cout<<sekundeuMinute(1072)<<endl;
- ispisiNputa(1000);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement