Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #1 numere prime
- #include<iostream>
- using namespace std;
- int main()
- {
- int n,c=0;
- cout<<"Introdu n"; cin>>n;
- for (int i=1; i<=n; i++)
- {
- if (n%i==0)
- c++;
- }
- if (c==2)
- cout<<"Numarul este prim";
- else
- cout<<"Numarul NU este prim";
- return 0;
- }
- #2 lista numere prime
- #include <iostream>
- #include <math.h>
- using namespace std;
- int main()
- {
- int i,x,d,OK;
- cin >> x;
- if (x>1)
- {
- cout << 2 << ' ';
- for (i = 3 ; i<=x ; i = i+2)
- {
- OK = 1;
- for (d = 3 ; d <= sqrt(i) and OK == 1; d = d+2)
- if (i % d == 0)
- OK = 0;
- if (OK==1)
- cout << i << ' ';
- }
- }
- return 0;
- }
- #3 primele n numere prime
- #include <iostream>
- #include <math.h>
- using namespace std;
- int main()
- {
- int i,x,d,OK;
- cin >> x;
- if (x>1)
- {
- cout << 2 << ' ';
- for (i = 3 ; i<=x ; i = i+2)
- {
- OK = 1;
- for (d = 3 ; d <= sqrt(i) and OK == 1; d = d+2)
- if (i % d == 0)
- OK = 0;
- if (OK==1)
- cout << i << ' ';
- }
- }
- return 0;
- }
- #4 afisarea unui numar cu o subdiviziune
- #include<iostream>
- #include<math.h>
- using namespace std;
- int main()
- {
- int n, k;
- int copien;
- cout<<"n=";
- cin>>n;
- if(n<0){n=n*(-1);}
- copien=n-1;
- cout<<"numarul cel mai mare mai mic decat "<<n<<" este = "<<copien;
- return 0;
- }
- #5 desc.
- #include<iostream>
- using namespace std;
- int x;
- int cifre;
- int main()
- {
- cout<<"x=";cin>>x;
- while(x>10){
- x=x/10;
- x++;}
- cout<<"x=" <<x;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement