Jump to content
Forum Roportal
Sign in to follow this  
lcz

unde gresesc?!

Rate this topic

Recommended Posts

numerele divizibile cu suma nr lor, care sunt <=n (de la tastatura)

 

intrebare: unde gresesc? :bataita:

 

#include<iostream.h>

int n, i, d;

int s;

 

void main()

{

cin>>n;

for(i=1;i<=n;i++)

{

s=0;

d=i;

while(d!=0)

{

s=s+d%10;

d=d/10;

}

if(d%s==0)

cout<<d<<endl;

}}

Share this post


Link to post
Share on other sites

am gasit !!!!!! :bataita: dar...., am alta: se cere sa se afiseze toate nr. de 3 cifre avand cifrele in ordine crescatoare si suma lor 18

 

#include<iostream.h>

int n,d,s,a,b,c,x;

void main()

{

cin>>n;

for(n=100;n<=999;n++)

{

s=0;

d=n;

while(d>100&&d<=999)

{

s=s+d%10;

d=d/10;

}

 

if(s==18)

{

a=n/100;

b=n/10%10;

c=n%10;

}

if(a>b)

{x=a;a=b;b=x;}

if(b>c)

{x=b;b=c;c=x;}

if(a>b)

{x=a;a=b;b=x;}

cout<<n<<endl;

}}

Share this post


Link to post
Share on other sites

#include<iostream.h>

 

int main() {

int i, j, k;

for(i=0;i<10;i++)

for(j=i;j<10;j++)

for(k=j;k<10;k++)

if(i + j + k == 18)

cout<<i<<j<<k<<endl;

return 0;

}

 

Pentru ordine strict crescatoare pui +1 la initializarea din for-uri (exemplu:j=i+1;...).

 

 

stdan

http://www.smartworks.ro/

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×