Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //////////////////////////////////////////////////////////////////////////////////
- //Прва задача:
- #include <iostream>
- using namespace std;
- int zbir_na_posledni_m(int broj, int cifri)
- {
- if(cifri>0)
- return broj%10+zbir_na_posledni_m(broj/10,cifri-1);
- else
- return 0;
- }
- int main()
- {
- int n,m;
- cin>>n>>m;
- cout<<zbir_na_posledni_m(n,m);
- return 0;
- }
- //////////////////////////////////////////////////////////////////////////////////
- //Втора задача:
- #include <iostream>
- using namespace std;
- int izostavi(int broj, int k)
- {
- if(broj==0)
- return 0;
- if(k==1)
- return izostavi(broj/10,k-1);
- return izostavi(broj/10,k-1)*10+broj%10;
- }
- int main()
- {
- int n,m;
- cin>>n>>m;
- cout<<izostavi(n,m);
- return 0;
- }
- //////////////////////////////////////////////////////////////////////////////////
- //Трета задача:
- #include <iostream>
- using namespace std;
- bool seSodrzi(int broj, int cifra)
- {
- if(broj==0)
- return false;
- if(broj%10==cifra)
- return true;
- return seSodrzi(broj/10,cifra);
- }
- void resenie(int broj1, int broj2)
- {
- if(seSodrzi(broj2,broj1%10)==true)
- cout<<"Cifrata "<<broj1%10<<" se sodrzi vo brojot "<<broj2<<endl;
- if(broj1>0)
- resenie(broj1/10,broj2);
- }
- int main()
- {
- int broj1, broj2;
- cin>>broj1>>broj2;
- resenie(broj1,broj2);
- return 0;
- }
- //////////////////////////////////////////////////////////////////////////////////
- //Четврта задача:
- #include <iostream>
- using namespace std;
- int main()
- {
- for(int i=100;i<=999;i++)
- {
- for(int j=0;j<=999;j++)
- {
- if((i+j)*(i+j)==i*1000+j)
- {
- if(i<100)
- cout<<0;
- if(i<10)
- cout<<0;
- cout<<i<<"-";
- if(j<100)
- cout<<0;
- if(j<10)
- cout<<0;
- cout<<j<<endl;
- }
- }
- }
- return 0;
- }
- //////////////////////////////////////////////////////////////////////////////////
- //Петта задача:
- #include <iostream>
- using namespace std;
- int zbir_na_kvadrati_na_cifri(int n)
- {
- if(n==0)
- return 0;
- else
- return (n%10)*(n%10)+zbir_na_kvadrati_na_cifri(n/10);
- }
- int main()
- {
- int n;
- cin>>n;
- for(int i=1;i<n;i++)
- if(zbir_na_kvadrati_na_cifri(i)==i)
- cout<<i<<endl;
- return 0;
- }
- //////////////////////////////////////////////////////////////////////////////////
- //Шеста задача:
- #include <iostream>
- using namespace std;
- bool eDeliv(int n)
- {
- if(n==0)
- return true;
- if(n%(n%10)==0)
- return eDeliv(n/10);
- else
- return false;
- }
- int main()
- {
- int n;
- cin>>n;
- for(int i=1;i<n;i++)
- {
- if(eDeliv(i))
- cout<<i<<endl;
- }
- return 0;
- }
- //////////////////////////////////////////////////////////////////////////////////
- //Седма задача:
- #include <iostream>
- using namespace std;
- int main()
- {
- int n,k;
- cin>>n>>k;
- int stepen=10;
- for(int i=1; ;i++)
- {
- if(stepen==i)
- stepen*=10;
- if(stepen*n+i == k*(i*10+n))
- {
- cout<<stepen*n+i;
- break;
- }
- }
- return 0;
- }
- //////////////////////////////////////////////////////////////////////////////////
- //Осма задача:
- #include <iostream>
- using namespace std;
- bool eProst(int n)
- {
- if(n==1)
- return false;
- if(n==3)
- return true;
- for(int i=3;i*i<n;i+=2)
- if(n%i==0)
- return false;
- return true;
- }
- bool eSuperProst(int n)
- {
- if(n==0)
- return true;
- if(eProst(n))
- return eProst(n/10);
- else
- return false;
- }
- int main()
- {
- int n;
- cin>>n;
- for(int i=1;i<n;++i)
- if(eSuperProst(i))
- cout<<i<<endl;
- return 0;
- }
- //////////////////////////////////////////////////////////////////////////////////
- //Деветта задача:
- #include <iostream>
- using namespace std;
- int dvoen_faktoriel(int n)
- {
- if(n<2)
- return 1;
- else
- return n*dvoen_faktoriel(n-2);
- }
- int main()
- {
- int n;
- cin>>n;
- cout<<dvoen_faktoriel(n);
- return 0;
- }
- //////////////////////////////////////////////////////////////////////////////////
- //Десетта задача:
- #include <iostream>
- using namespace std;
- int stepen2(int n)
- {
- if(n==0)
- return 1;
- else
- return 2*stepen2(n-1);
- }
- int main()
- {
- int n,st=1;
- cin>>n;
- while(stepen2(st)-1<n)
- {
- cout<<stepen2(st)-1<<endl;
- st++;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement