Sunteți pe pagina 1din 5

1.Afisati toate nr nat de 3 cifre div cu k, care se citeste. #include<iostream.

h> int x,k; void main() { cout<<"k= ";cin>>k; cout<<"Numerele divizibile cu "<<k<<" sunt: "; for(x=100;x<=999;x++) if(x%k==0) cout<<x<<", "; } 2.Afisati toate nr naturale mai mici sau egale cu n citit divizibile cu A, dar nedivizibile cu B(care se citesc). #include<iostream.h> int x,n,A,B; void main() { cout<<"A= ";cin>>A; cout<<"B= ";cin>>B; cout<<"n= ";cin>>n; cout<<"Numerele divizibile cu "<<A<<", dar nedivizibile cu "<<B<<" sunt: "; for(x=1;x<=n;x++) if(x%A==0 && x%B!=0) cout<<x<<", "; cout<<endl; } 3.Afisati primele n patrate perfecte (n natural se citeste.) #include<iostream> int x,n; void main() { cout<<"n= ";cin>>n; cout<<"Primele "<<n<<" patrate perfecte sunt: "; for(x=1;x<=n;x++) cout<<x*x<<", "; cout<<endl; } 4.Afisati nr prime mai mici decat 1000. #include<iostream> int x,d,i; void main() { cout<<"Numerele prime mai mici decat 1000 sunt: "; for(x=1;x<1000;x++) { i=0; for(d=1;d<=x;d++) if(x%d==0) i=i+1; if (i==2) cout<<x<<", "; } cout<<endl; }

5.Afisati nr prime din [A,B]. #include<iostream.h> int x,d,i,A,B; void main() { cout<<"A= ";cin>>A; cout<<"B= ";cin>>B; cout<<"Numerele prime din interval sunt: "; for(x=A;x<=B;x++) { i=0; for(d=1;d<=x;d++) if(x%d==0) i=i+1; if (i==2) cout<<x<<", "; } cout<<endl; } 6. Afisati nr prime din [A,B] cu min 4 divizori. #include<iostream.h> int x,d,i,A,B; void main() { cout<<"A= ";cin>>A; cout<<"B= ";cin>>B; cout<<"Numerele cu 4 divizori din interval sunt: "; for(x=A;x<=B;x++) { i=0; for(d=1;d<=x;d++) if(x%d==0) i=i+1; if(i<=4) cout<<x<<", "; } cout<<endl; } 7. Afisati divizorii unui nr natural din [A,B]. #include<iostream.h> int x,d,i,A,B; void main() { cout<<"A= ";cin>>A; cout<<"B= ";cin>>B; for(x=A;x<=B;x++) { cout<<"Divizorii lui "<<x<<" sunt: "; for(d=1;d<=x;d++) if (x%d==0) cout<<d<<", ";cout<<endl; } }

8. Afisati suma divizorii unui nr natural din [A,B]. #include<iostream.h> int x,d,A,B,S; void main() { cout<<"A= ";cin>>A; cout<<"B= ";cin>>B; for(x=A;x<=B;x++) { S=0; for(d=1;d<=x;d++) if (x%d==0) S=S+d; cout<<"Suma divizorii lui "<<x<<" este "<<S<<endl; } } 9. Triunghi de numere. #include<iostream.h> int i; void main() { for(i=1;i<=10;i++) cout<<1<<" "; cout<<endl; } 10.Afisati posibilatatile de descompunere ale unui nr natural in suma a 2 nr naturale. #include<iostream.h> int a,x,b=0; void main() { cout<<"x= ";cin>>x; for(a=0;a<=x;a++) { b=x-a; cout<<x<<"="<<a<<"+"<<b<<endl; } } 11. Afisati descompunerea unui nr natural in suma patratelor a 2 nr nat. #include<iostream.h> #include<math.h> int a,x,b; void main() { cout<<"x= ";cin>>x; for(a=0;a<=int(sqrt(x));a++) { for(b=0;b<=int(sqrt(x));b++) if(a*a+b*b==x) cout<<x<<"="<<a*a<<"+"<<b*b<<endl; } }

12.Primele n numere prime #include<iostream> int x=0,i=1,n,d,nr; void main() { cout<<"n= ";cin>>n; cout<<"Primele "<<n<<" nr prime sunt: "; while(i<=n) { x=x+1; nr=0; for(d=1;d<=x;d++) if (x%d==0) nr=nr+1; if (nr==2) { i=i+1; cout<<x<<", "; } } cout<<endl; } 13.Daca 3 nr citite sunt poz, afiseaza suma cuburilor, produsul si media arit, altfel afiseaza NU. #include<iostream> float a,b,c; void main() { cout<<"a=";cin>>a; cout<<"b=";cin>>b; cout<<"c=";cin>>c; if(a>=0 && b>=0 && c>=0) { cout<<"Suma cuburilor este "<<a*a*a+b*b*b+c*c*c<<endl; cout<<"Produsul numerelor= "<<a*b*c<<endl; cout<<"Media aritmetica a nr este "<<(a+b+c)/3<<endl; } else cout<<"NU"<<endl; } 14.Daca 3 nr citite sunt poz si pare, afiseaza media arit, suma patratelor si suma lor, altfel INCORECT. #include<iostream> int a,b,c; void main() { cout<<"a=";cin>>a; cout<<"b=";cin>>b; cout<<"c=";cin>>c; if(a>=0 && b>=0 && c>=0 && a%2==0 && b%2==0 && c%2==0) { cout<<"Media aritmetica a nr este "<<(a+b+c)/3<<endl; cout<<"Suma patratelor este "<<a*a+b*b+c*c<<endl; cout<<"Suma numerelor= "<<a+b+c<<endl; } else cout<<"INCORECT"<<endl; }

15.Daca 3 nr citite sunt poz si pare, afiseaza suma lor, altfel daca sunt impare poz, afiseaza produsul #include<iostream> int a,b,c; void main() { cout<<"a=";cin>>a; cout<<"b=";cin>>b; cout<<"c=";cin>>c; if(a>=0 && b>=0 && c>=0 && a%2==0 && b%2==0 && c%2==0) cout<<"Suma numerelor= "<<a+b+c<<endl; else if(a>=0 && b>=0 && c>=0 && a%2!=0 && b%2!=0 && c%2!=0) cout<<"Produsul numerelor= "<<a*b*c<<endl; } 16. Daca 3 nr citite sunt poz si pare, afiseaza suma lor, altfel daca sunt impare poz, afiseaza produsul #include<iostream> float a,b,c,d; void main() { cout<<"a=";cin>>a; cout<<"b=";cin>>b; cout<<"c=";cin>>c; cout<<"d=";cin>>d; if(a>0 && b>0 && c>=0 && d>0) cout<<"Suma numerelor= "<<a+b+c+d<<endl; else if(a<0 && b<0 && c<0 && d<0) cout<<"Media aritmetica este "<<(a+b+c+d)/4<<endl; } 17. Daca 3 nr pot fi lat triunghi afisati perimetrul si latura mai mare. #include<iostream> #include<math.h> float a,b,c,p; void main() { cout<<"a=",cin>>a; cout<<"b=";cin>>b; cout<<"c=",cin>>c; if ((a>0)&&(b>0)&&(c>0)&&(a+b>c)&&(a+c>b)&&(b+c>a)) { cout<<a<<", "<<b<<" si "<<c<<" pot fi laturile unui triunghi"<<endl; if(a>b && a>c) cout<<"Latura mai mare este "<<a<<endl; else if (b>a && b>c) cout<<"Latura mai mare este "<<b<<endl; else cout<<"Latura mai mare este "<<c<<endl; p=(a+b+c)/2; cout<<"Perimetrul triunghiului este "<<sqrt(p*(p-a)*(p-b)*(p-c))<<endl; } }