Probleme recapitulare
1) #include<iostream>
using namespace std;
int main()
{int x,min=9,a,b,c,i,n;
cout<<"x=";cin>>x;
a=x/100;
b=x/10%10;
c=x%10;
if(a<b && a<c)i=1;
else if(b<c)i=2;
else i=3;
switch(i)
{case 1: x=x%100;break;
case 2: x=a*10+c;break;
case 3: x=x/10;break;}
cout<<x;
}
2) #include<iostream>
using namespace std;
int main()
{int n,r,p,d,ok1=1,ok2=1,s;
cout<<"n=";cin>>n;
s=0;
while(n>9)
{if(s!=0)n=s;
p=n;s=0;
while(p){s=s+p%10;p=p/10;}
n=s;
}
cout<<n;
}
3) #include<iostream>
using namespace std;
int main()
{int ok=0,n,p,i,s;
cout<<"n=";cin>>n;
for(i=1;i<=n;i++)
{s=0;p=i;
while(p)
{s=s+p%10;p=p/10;}
if(n==i+s){ok=1;break;}
}
cout<<i<<"+"<<s<<"="<<n<<endl;
if(ok==1)cout<<"Numarul este deosebit";
else cout<<"NU";
}
4) #include<iostream>
using namespace std;
int main()
{int n,x,y=1,i,s1=0,s2=0;
cin>>n;
s1=29;
for(i=20;i<=n;i++)
{x=i;s2=0;
while(x>0)
{
s2=s2+1;
x=x/10;
}
s1=s1+s2;
}
cout<<s1;
}
5) #include<iostream>
using namespace std;
int main()
{int n,r,p,d,ok1=1,ok2=1;
for(n=20;n<1000;n++)
{ok1=1;ok2=1;
for(d=2;d<=n/2;d++)
if(n%d==0)ok1=0;
p=n;
if(ok1==1)
{while(p)
{p=p/10;
for(d=2;d<=p/2;d++)
if(p%d==0)ok2=0;}
}
if(ok1==1 && ok2==1)
cout<<n<<" este superprim"<<endl;
}
}
6) #include<iostream>
using namespace std;
int main()
{int a,b,n,x,y=1,j,i,i1,j1,ok1,ok2;
cout<<"n=";cin>>n;
a=n+1;
b=n-1;
while(y==1)
{ok1=1;ok2=1;
for(i=2;i<=a/2;i++)
if(a%i==0)ok1=0;
for(j=2;j<=b/2;j++)
if(b%j==0)ok2=0;
if(ok1==1){cout<<a<<";";y=0;}
if(ok2==1){cout<<b<<";";y=0;}
if(ok1==0 && ok2==0){a++; b--;}
}
}
7) #include<iostream>
using namespace std;
int main()
{int n,r,p,d,ok1=1,ok2=1;
for(n=100;n<1000;n++)
{ok1=1;ok2=1;
for(d=2;d<=n/2;d++)
if(n%d==0)ok1=0;
if(ok1==1)r=(n%10)*100+(n/10%10)*10+(n/100);
for(d=2;d<=r/2;d++)
if(r%d==0)ok2=0;
if(ok1==1 && ok2==1)
cout<<n<<";"<<r<<endl;
}
}
sâmbătă, 18 septembrie 2010
by DlMuresan
Categories:
info
|