• Задача 5.

    #include <iostream>
    using namespace std;
    
    double factoriel(unsigned int num);
    
    int main()
    {
    	int n, m, k;
    	cout << "n = ";
    	cin >> n;
    	cout << "m = ";
    	cin >> m;
    	cout << "k = ";
    	cin >> k;
    	double result;
    	cout<<factoriel(m)<<endl;
        cout<<factoriel(n)<<endl;
        cout<<factoriel(k)<<endl;
    	result = ( factoriel(m) + factoriel(n) + factoriel(k) )/( factoriel(5) + factoriel(3) );
    	cout << "(n!+m!+k!):(3!+5!) = " << result << endl;
    	return 0;
    }
    
    double factoriel(unsigned int num)
    {
    	if( 0 == num ) return 1;
    	double mult = 1;
    	do {
    		mult*=num;
    	}
    	while(--num);
    	return mult;
    }
    

    Задача 6.

    #include <iostream>
    
    using namespace std;
    
    double Area(double a, double b, double &P, double &S);
    
    int main()
    {
    	double a1, b1, a2, b2, Area1, Area2, P1, P2;
        cout << "Vyvedete stranite na vynshniq pravoygylnik:"<<endl;
    	cout << "a1 = ";
    	cin >> a1;
    	cout << "b = ";
    	cin >> b1;
        cout << "Vyvedete stranite na vytreshniq pravoygylnik:"<<endl;
    	cout << "a2 = ";
    	cin >> a2;
    	cout << "b2 = ";
    	cin >> b2;
    	Area (a1, b1, P1, Area1);
    	Area (a2, b2, P2, Area2);
    	cout << "Liceto na ocvetenata chast = " << Area1 - Area2 << endl;
    	cout << "Obikolkata na ocvetenata chast = " << P1 + P2 << endl;
        return 0;
    }
    
    double Area(double a, double b, double &P, double &S)
    {
    	P = 2 * a + 2 * b;
    	S = a * b;
    }
    

    Задача 7.

    #include <iostream>
    
    using namespace std;
    
    double fib(int n);
    
    int main()
    {
    	int k,f,i;
        cout << "k = ";
    	cin >> k;
    	i=1;
    	while (fib(i)<=k)
    	{
        
           cout<<fib(i)<<endl;
           i++; 
        }
        return 0;
    }
    
    double fib(int n)
    {
        double a1, a2, a3;
    	a1=1;
    	a2=1;
    	if (n==1 || n==2) return 1;
    	if (n==3) return 2;
    	for (int i=3; i<=n; i++)
    	{
            a3= a1+a2;
            a1=a2;
            a2=a3;
    	}
    	return a3;
    }
    

    Задача 8.

    #include<iostream>
    //#include<cmath>
    using namespace std;
    double f1(double a,int n)
    {
        if (n==0) return 1;
        if (n>0) return a*f1(a,n-1);
        if (n<0) return 1.0/f1(a,-n);
    }
    int main()
    {
      double p,q,k,r,A;
      cout<<"p=";
      cin>>p;
      cout<<"k=";
      cin>>k;
      cout<<"q=";
      cin>>q;
      cout<<"r=";
      cin>>r;
      A=(f1(p,k)-f1(q,r))/2;
      cout<<"A="<<A<<endl;
    return 0;
    }
    
    

    Задача 9.

    #include<iostream>
    #include<cmath>
    using namespace std;
    int f1(double a,double b,double c, double &x1, double &x2)
    {
     if (a==0)
        if (b==0)
            if (c==0) 
            {
                cout<<"Всяко х е решение"<<endl;
                return 0;
            }
            else
            {
                cout<<"Няма решение"<<endl;
                return 0;
            }
        else
        {
            cout<<"x = "<<-c/b<<endl;
            return 0;
        }
    else
    {
     double D;
     D=b*b-4*a*c;
     if (D<0)
     {
         cout<<"Няма реални корени"<<endl;
         return 0;
     }
     else
     {
     x1=(-b-sqrt(D))/(2*a);
     x2=(-b-sqrt(D))/(2*a);
     return 1;
     }
    }
    }
    int main()
    {
      double A,a,b,c,x1,x2,rez;
      cout<<"a=";
      cin>>a;
      cout<<"b=";
      cin>>b;
      cout<<"c=";
      cin>>c;
      rez=f1(a,b,c,x1,x2);
      if (rez==1)
      {
      A=x1+2*x2;
      cout<<"A="<<A<<endl;
      }
      else 
      cout<<"Изразът не може да получи стойност"<<endl;
    return 0;
    }
    
    
    

    Задача 10.

    #include<iostream>
    using namespace std;
    double fNOD(int a,int b)
    {
        while(a!=b)
        if(a>b)a=a-b;
        else b=b-a;
        return a;
    }
    int main()
    {
      double A,a,b,c,d;
      cout<<"a=";
      cin>>a;
      cout<<"b=";
      cin>>b;
      cout<<"c=";
      cin>>c;
      cout<<"d=";
      cin>>d;
      A=fNOD(a,b)+2*fNOD(c,d);
      cout<<"A="<<A<<endl;
    return 0;
    }
    

    Задача11.

    #include<iostream>
    using namespace std;
    double fNOD(int a,int b)
    {
        while(a!=b)
        if(a>b)a=a-b;
        else b=b-a;
        return a;
    }
    int main()
    {
      double NOK,a,b,c,d;
      cout<<"a=";
      cin>>a;
      cout<<"b=";
      cin>>b;
      NOK=(a*b)/fNOD(a,b);
      cout<<"NOK(a,b)="<<NOK<<endl;
    return 0;
    }
    
    

    Задача 12.

    #include<iostream>
    #include<math.h>
    using namespace std;
    double fNOD(int a,int b)
    {
        while(a!=b)
        if(a>b)a=a-b;
        else b=b-a;
        return a;
    }
    int main()
    {
      int i,mas[20];
      for(i=0;i<20;i++)
      {
        cout<<"mas["<<i<<"]=";
        cin>>mas[i];
    
      }
      int p=fNOD(mas[0],mas[1]);
      for(i=2;i<20;i++)
      {
          p=fNOD(p,mas[i]);
      }
      cout<<"NOD="<<p<<endl;
    return 0;
    }
    
    

    Задача 13.

    #include<iostream>
    using namespace std;
    int f1(double a,double b,double c)
    {
        if(a<b+c && b<c+a && c<a+b) return 1;
        else return 0;
    }
    void f2(double a,double b,double c)
    {
        if(a==b && b==c) cout<<"ravnostranen";
        else
        if (a==b || b==c || c==a) cout<<"ravnobedren";
        else
        cout<<"raznostranen";
    }
    int main()
    {
        int n,i,j,a[50][3],k;
        cout<<"n=";
        cin>>n;
        for(i=0;i<n;i++)
        for(j=0;j<3;j++)
        {
            cout<<"a["<<i<<"]["<<j<<"]=";
            cin>>a[i][j];
        }
        for(i=0;i<n;i++)
        {
            cout<<a[i][0]<<"  "<<a[i][1]<<"  "<<a[i][2]<<endl;
            k=f1(a[i][0],a[i][1],a[i][2]);
            if(k==1)
            {
                cout<<"Yes ";
                f2(a[i][0],a[i][1],a[i][2]);
            }
            else
            cout<<"No ";
            cout<<endl;
        }
    return 0;
    }
    
    

    Задача 14.

    #include<iostream>
    using namespace std;
    void InputArray(int k,int arr[])
    {
    for(int i=0;i<k;i++)
    {
       cout<<"arr["<<i<<"]=";
       cin>>arr[i];
    }
    }
    void DisplayArray(int k,int arr[])
    {
       for(int i=0;i<k;i++) cout<<arr[i]<<" ";
       cout<<endl;
    }
    void BinaryCode(int p)
    {
        if(p<2) cout<<1;
        else
        {
           BinaryCode(p/2);
           cout<<p%2;
        }
    }
    int main()
    {
      int i,n,mas[30];
      cin>>n;
      InputArray(n,mas);
      DisplayArray(n,mas);
      for(i=0;i<n;i++)
      {
          BinaryCode(mas[i]);
          cout<<" ";
      }
    return 0;
    }
    

    Задача 15.

    #include<iostream>
    using namespace std;
    void InputArray(int k,int arr[])
    {
    for(int i=0;i<k;i++)
    {
       cout<<"arr["<<i<<"]=";
       cin>>arr[i];
    }
    }
    void DisplayArray(int k,int arr[])
    {
       for(int i=0;i<k;i++) cout<<arr[i]<<" ";
       cout<<endl;
    }
    int Sum(int p)
    {
        int ost,s=0;
        while(p!=0)
        {
            ost=p%10;
            p=p/10;
            s=s+ost;
        }
        return s;
    }
    int main()
    {
        int i,n,A[40],B[40];
        cin>>n;
        InputArray(n,A);
        for(i=0;i<n;i++)
        {
            B[i]=Sum(A[i]);
        }
        DisplayArray(n,B);
        return 0;
    }
    

    Задача 16.

    #include<iostream>
    using namespace std;
    void InputArray(int k,int arr[])
    {
    for(int i=0;i<k;i++)
    {
       cout<<"arr["<<i<<"]=";
       cin>>arr[i];
    }
    }
    void DisplayArray(int k,int arr[])
    {
       for(int i=0;i<k;i++) cout<<arr[i]<<" ";
       cout<<endl;
    }
    int Mul(int p)
    {
        int ost,s=1;
        while(p!=0)
        {
            ost=p%10;
            p=p/10;
            s=s*ost;
        }
        return s;
    }
    
    void SortArray(int k,int *q)
    {
        int temp;
        for(int i=0;i<k-1;i++)
        for(int j=0;j<k-i-1;j++)
        if(*(q+j)>*(q+j+1)) 
        {
            temp=*(q+j);
            *(q+j)=*(q+j+1);
            *(q+j+1)=temp;
        }
    }
    
    int main()
    {
        int i,n,A[40],B[40],f,m=0;
        cin>>n;
        InputArray(n,A);
        for(i=0;i<n;i++)
        {
            f=Mul(A[i]);
            if (f%3==0) {
                            B[m]=f; 
                            m++;
                        }
        }
        SortArray(m,B);
        DisplayArray(m,B);
        return 0;
    }