Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- using namespace std;
- int s(int n)
- {
- if(n==0)
- return 0;
- else
- {
- if(n%2 == 0)
- return s(n-2)+n;
- else
- return s(n-1)+n;
- }
- }
- int main()
- {
- int n;
- cin>>n;
- cout<<s(n);
- }
- //-----------------------------------------------------------------------------------------------------------------\\
- #include <iostream>
- #include <conio.h>
- using namespace std;
- int s1(int n)
- {
- if(n<=0)
- return 0;
- else
- if(n%2 == 0)
- return s1(n-1)+n;
- else
- return s1(n-2)+n;
- }
- int main()
- {
- int n;
- cin>>n;
- cout<<s1(n);
- }
- //------------------------------------------------------------------------------------------------------------------\\
- #include <iostream>
- #include <conio.h>
- using namespace std;
- int prim(int n,int i)
- {
- if(i>n/2)
- return 1;
- else
- if (n%i==0)
- return 0;
- else
- return prim(n,i+1);
- }
- int main()
- {
- int n;
- cin>>n;
- if(prim(n,2))
- cout<<"Prim";
- else
- cout<<"Nu este prim";
- }
- //----------------------------------------------------------------------------------------------------------------\\
- #include <iostream>
- #include <conio.h>
- using namespace std;
- int prim(int n,int i)
- {
- if(i>n/2)
- return 1;
- else
- if (n%i==0)
- return 0;
- else
- return prim(n,i+1);
- }
- int main()
- {
- int n, s = 0, i;
- cin>>n;
- for(i=2;i<n;i++)
- if(prim(i,2))
- s++;
- cout<<s;
- }
- //----------------------------------------------------------------------------------------------------------------\\
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement