Advertisement
add1ctus

Задаче

Oct 6th, 2015
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.85 KB | None | 0 0
  1. //////////////////////////////////////////////////////////////////////////////////
  2. //Прва задача:
  3.  
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8. int zbir_na_posledni_m(int broj, int cifri)
  9. {
  10.     if(cifri>0)
  11.         return broj%10+zbir_na_posledni_m(broj/10,cifri-1);
  12.     else
  13.         return 0;
  14. }
  15.  
  16. int main()
  17. {
  18.     int n,m;
  19.     cin>>n>>m;
  20.     cout<<zbir_na_posledni_m(n,m);
  21.     return 0;
  22. }
  23.  
  24. //////////////////////////////////////////////////////////////////////////////////
  25. //Втора задача:
  26.  
  27. #include <iostream>
  28.  
  29. using namespace std;
  30.  
  31. int izostavi(int broj, int k)
  32. {
  33.     if(broj==0)
  34.         return 0;
  35.     if(k==1)
  36.         return izostavi(broj/10,k-1);
  37.     return izostavi(broj/10,k-1)*10+broj%10;
  38. }
  39.  
  40. int main()
  41. {
  42.     int n,m;
  43.     cin>>n>>m;
  44.     cout<<izostavi(n,m);
  45.     return 0;
  46. }
  47.  
  48.  
  49. //////////////////////////////////////////////////////////////////////////////////
  50. //Трета задача:
  51.  
  52. #include <iostream>
  53.  
  54. using namespace std;
  55.  
  56. bool seSodrzi(int broj, int cifra)
  57. {
  58.     if(broj==0)
  59.         return false;
  60.     if(broj%10==cifra)
  61.         return true;
  62.     return seSodrzi(broj/10,cifra);
  63. }
  64.  
  65. void resenie(int broj1, int broj2)
  66. {
  67.     if(seSodrzi(broj2,broj1%10)==true)
  68.         cout<<"Cifrata "<<broj1%10<<" se sodrzi vo brojot "<<broj2<<endl;
  69.     if(broj1>0)
  70.         resenie(broj1/10,broj2);
  71. }
  72.  
  73. int main()
  74. {
  75.     int broj1, broj2;
  76.     cin>>broj1>>broj2;
  77.     resenie(broj1,broj2);
  78.     return 0;
  79. }
  80.  
  81.  
  82. //////////////////////////////////////////////////////////////////////////////////
  83. //Четврта задача:
  84.  
  85. #include <iostream>
  86.  
  87. using namespace std;
  88.  
  89. int main()
  90. {
  91.     for(int i=100;i<=999;i++)
  92.     {
  93.         for(int j=0;j<=999;j++)
  94.         {
  95.             if((i+j)*(i+j)==i*1000+j)
  96.             {
  97.                 if(i<100)
  98.                     cout<<0;
  99.                 if(i<10)
  100.                     cout<<0;
  101.                 cout<<i<<"-";
  102.                 if(j<100)
  103.                     cout<<0;
  104.                 if(j<10)
  105.                     cout<<0;
  106.                 cout<<j<<endl;
  107.             }
  108.         }
  109.     }
  110.     return 0;
  111. }
  112.  
  113. //////////////////////////////////////////////////////////////////////////////////
  114. //Петта задача:
  115.  
  116. #include <iostream>
  117.  
  118. using namespace std;
  119.  
  120. int zbir_na_kvadrati_na_cifri(int n)
  121. {
  122.     if(n==0)
  123.         return 0;
  124.     else
  125.         return (n%10)*(n%10)+zbir_na_kvadrati_na_cifri(n/10);
  126. }
  127.  
  128. int main()
  129. {
  130.     int n;
  131.     cin>>n;
  132.     for(int i=1;i<n;i++)
  133.         if(zbir_na_kvadrati_na_cifri(i)==i)
  134.             cout<<i<<endl;
  135.     return 0;
  136. }
  137.  
  138. //////////////////////////////////////////////////////////////////////////////////
  139. //Шеста задача:
  140.  
  141. #include <iostream>
  142.  
  143. using namespace std;
  144.  
  145. bool eDeliv(int n)
  146. {
  147.     if(n==0)
  148.         return true;
  149.     if(n%(n%10)==0)
  150.         return eDeliv(n/10);
  151.     else
  152.         return false;
  153. }
  154.  
  155. int main()
  156. {
  157.     int n;
  158.     cin>>n;
  159.     for(int i=1;i<n;i++)
  160.     {
  161.         if(eDeliv(i))
  162.             cout<<i<<endl;
  163.     }
  164.     return 0;
  165. }
  166.  
  167. //////////////////////////////////////////////////////////////////////////////////
  168. //Седма задача:
  169. #include <iostream>
  170.  
  171. using namespace std;
  172.  
  173. int main()
  174. {
  175.     int n,k;
  176.     cin>>n>>k;
  177.     int stepen=10;
  178.     for(int i=1; ;i++)
  179.     {
  180.         if(stepen==i)
  181.             stepen*=10;
  182.         if(stepen*n+i == k*(i*10+n))
  183.         {
  184.             cout<<stepen*n+i;
  185.             break;
  186.         }
  187.     }
  188.     return 0;
  189. }
  190.  
  191. //////////////////////////////////////////////////////////////////////////////////
  192. //Осма задача:
  193.  
  194. #include <iostream>
  195.  
  196. using namespace std;
  197.  
  198. bool eProst(int n)
  199. {
  200.     if(n==1)
  201.         return false;
  202.     if(n==3)
  203.         return true;
  204.     for(int i=3;i*i<n;i+=2)
  205.         if(n%i==0)
  206.             return false;
  207.     return true;
  208. }
  209.  
  210. bool eSuperProst(int n)
  211. {
  212.     if(n==0)
  213.         return true;
  214.     if(eProst(n))
  215.         return eProst(n/10);
  216.     else
  217.         return false;
  218. }
  219.  
  220. int main()
  221. {
  222.     int n;
  223.     cin>>n;
  224.     for(int i=1;i<n;++i)
  225.         if(eSuperProst(i))
  226.             cout<<i<<endl;
  227.     return 0;
  228. }
  229.  
  230. //////////////////////////////////////////////////////////////////////////////////
  231. //Деветта задача:
  232.  
  233. #include <iostream>
  234.  
  235. using namespace std;
  236.  
  237. int dvoen_faktoriel(int n)
  238. {
  239.     if(n<2)
  240.         return 1;
  241.     else
  242.         return n*dvoen_faktoriel(n-2);
  243. }
  244.  
  245. int main()
  246. {
  247.     int n;
  248.     cin>>n;
  249.     cout<<dvoen_faktoriel(n);
  250.     return 0;
  251. }
  252.  
  253. //////////////////////////////////////////////////////////////////////////////////
  254. //Десетта задача:
  255.  
  256. #include <iostream>
  257.  
  258. using namespace std;
  259.  
  260. int stepen2(int n)
  261. {
  262.     if(n==0)
  263.         return 1;
  264.     else
  265.         return 2*stepen2(n-1);
  266. }
  267.  
  268. int main()
  269. {
  270.     int n,st=1;
  271.     cin>>n;
  272.     while(stepen2(st)-1<n)
  273.     {
  274.         cout<<stepen2(st)-1<<endl;
  275.         st++;
  276.     }
  277.     return 0;
  278. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement