Jump to content
LegendKiller

O mica problema c++

Recommended Posts

Posted

Iar ma confrunt cu o mica problema ....

Am problema : Sa se determine cea mai mica cifra impara dintr-un numar.

#include <iostream>

using namespace std;

int main()
{
long int n,min,c,r,i;
{
cout<<"n="; cin>>n;
min = 0;
if(i%2!=0);
}
cout<<min;
return 0;
}

Si de aici nu mai stiu .

Posted

Verifica fiecare cifra din numar. Daca vrei sa lucrezi cu numere mari poti apela la vectori.


#include <stdio.h>
int main(){
long i,n,min=10;
scanf("%d",&n);
while(n){
if(((n%10)%2==1)&&((n%10)%2)<min)
min=n%10;
n/=10;
}
if(min<10) printf("%d",min); else printf("Nu exista");
return 0;
}

Posted

#include<iostream>

using namespace std;

int main()

{

long n,min;

cout<<"n=";cin>>n;

min=10;

do

{if(((n%10)%2==1)&&(n%10<=min))

min=n%10;

n=n/10;

}while (n>0);

cout<<"cifra este "<<min<<endl;

system ("pause");

}

Cum a zis si em verifici daca ultima cifra este si impara si mai mare ca min. Insa el verifica daca ultima cifra impartita la 2 este mai mare ca min.

Posted

Daca vrei varianta pascal iti fac eu problema

var n,c,min:integer;

begin

read(n);

min:=10;

while n<>0 do begin

c:=n mod 10

if (c mod 2<>0) and (c<min) then min:=c;

n:=n div 10;

end;

if min<10 then write('Cea mai mica cifra impara este', min);

end.

Daca vrei C++ o traduci :D

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...