Imi trebuie toate cele 4 prob in C++
Răspunsuri la întrebare
1.
#include <iostream>
using namespace std;
int main()
{
int n,d,x=0;
cin>>n;
for (d=1;d<=n;d++)
if (n%d==0) x++;
if (x==2) cout<<"numar prim";
return 0;
}
2.
#include <iostream>
using namespace std;
int main()
{
int n,d,p,x=0;
cin>>n;
for (d=1;d<=n;d++)
if (d*d==n) p = d;
for (d=1;d<=p;d++)
if (p%d==0) x++;
if (x==2) cout<<"DA";
else cout<<"NU";
return 0;
}
3.
#include <iostream>
using namespace std;
int main()
{
int n,i,d,x;
cin>>n;
for (i=1;i<=n;i++)
{
x=0;
for (d=1;d<=i;d++)
if (i%d==0) x++;
if (x==2) cout<<i<<" ";
}
return 0;
}
4.
#include <iostream>
using namespace std;
int main()
{
int i,d,x;
for (i=100;i<=999;i++)
{
x=0;
for (d=1;d<=i;d++)
if (i%d==0) x++;
if (x==2 || i%2==0) cout<<i<<" ";
}
return 0;
}
Sper că te-am ajutat, coroană? :)