LegendKiller Posted February 11, 2010 Report Posted February 11, 2010 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 . Quote
em Posted February 11, 2010 Report Posted February 11, 2010 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;} Quote
H4e Posted February 12, 2010 Report Posted February 12, 2010 #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. Quote
alex_cismas Posted February 19, 2010 Report Posted February 19, 2010 Daca vrei varianta pascal iti fac eu problemavar n,c,min:integer;beginread(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 Quote