Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* VARIANTA 2 SUBIECTUL III EXERCITIUL 2 a+b */
- #include <iostream>
- using namespace std;
- int nr(int a,int b)
- {
- int i,c=0;
- if (a<=b)
- {for (i=a;i<b;i++)
- c++;
- }
- else
- {
- for (i=b;i<a;i++)
- c++;
- }
- return c;
- }
- int divizori(int a,int k)
- {
- int c=0,i,m,x;
- for (i=1;i<=99;i++)
- if (a*i>9999)
- break;
- m=i;
- for (i=2;i<=m;i++)
- {
- x=nr(a,a*i);
- if (x%a==0)
- c++;
- }
- return c;
- }
- int main()
- {
- cout<<" "<<divizori(2007,4);
- return 0;
- }
- --------------------------------------------------------------------------------------------------
- /* Numar rotund */
- #include <iostream>
- using namespace std;
- int baza(int n)
- {
- int nr=0;
- while (n)
- {
- nr=nr*10+n%2;
- n=n/2;
- }
- return nr;
- }
- void rezolva()
- {
- int unu=0,zero=0,cop,n;
- cout<<"n= ";cin>>n;
- cop=baza(n);
- while (cop)
- {
- if (cop%10==0)
- zero++;
- else
- unu++;
- cop=cop/10;
- }
- if (zero==unu)
- cout<<n<<" este numar rotund. ";
- else
- cout<<n<<" nu este numar rotund. ";
- cout<<'\n'<<"Numarul "<<n<<" in baza 2 este "<<baza(n)<<". ";
- }
- int main()
- {
- rezolva();
- return 0;
- }
- -------------------------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement