Advertisement
icatalin

tema 30.10

Oct 29th, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.42 KB | None | 0 0
  1. /* VARIANTA 2 SUBIECTUL III EXERCITIUL 2 a+b */
  2.  
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. int nr(int a,int b)
  8. {
  9.     int i,c=0;
  10.     if (a<=b)
  11.     {for (i=a;i<b;i++)
  12.     c++;
  13.     }
  14.     else
  15.     {
  16.     for (i=b;i<a;i++)
  17.     c++;
  18.     }
  19.     return c;
  20. }
  21.  
  22. int divizori(int a,int k)
  23. {
  24.     int c=0,i,m,x;
  25.  
  26.     for (i=1;i<=99;i++)
  27.     if (a*i>9999)
  28.     break;
  29.  
  30.     m=i;
  31.  
  32.     for (i=2;i<=m;i++)
  33.     {
  34.         x=nr(a,a*i);
  35.         if (x%a==0)
  36.             c++;
  37.     }
  38.  
  39.     return c;
  40. }
  41.  
  42. int main()
  43. {
  44.    cout<<" "<<divizori(2007,4);
  45.  
  46.  return 0;
  47. }
  48.  
  49. --------------------------------------------------------------------------------------------------
  50.  
  51. /* Numar rotund */
  52.  
  53. #include <iostream>
  54.  
  55. using namespace std;
  56.  
  57. int baza(int n)
  58. {
  59.     int nr=0;
  60.     while (n)
  61.     {
  62.         nr=nr*10+n%2;
  63.         n=n/2;
  64.     }
  65.     return nr;
  66. }
  67.  
  68. void rezolva()
  69. {
  70.     int unu=0,zero=0,cop,n;
  71.     cout<<"n= ";cin>>n;
  72.     cop=baza(n);
  73.     while (cop)
  74.     {
  75.         if (cop%10==0)
  76.             zero++;
  77.         else
  78.             unu++;
  79.         cop=cop/10;
  80.     }
  81.     if (zero==unu)
  82.         cout<<n<<" este numar rotund. ";
  83.     else
  84.         cout<<n<<" nu este numar rotund. ";
  85.  
  86.         cout<<'\n'<<"Numarul "<<n<<" in baza 2 este "<<baza(n)<<". ";
  87. }
  88.  
  89. int main()
  90. {
  91.     rezolva();
  92.     return 0;
  93. }
  94.  
  95. -------------------------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement