Hallar el dígito mayor de un numero
//Hallar el dígito mayor de un numero ingresado por teclado
#include<iostream>
using namespace std ;
int main(){
int numero,i,d,mayor;
i=0;
cout<<"Ingrese numero :"<<endl;
cin>>numero;
while(numero>0){
if(i==0){
d=numero%10;
mayor=d;
numero=numero/10;
i++;
}else{
d=numero%10;
numero=numero/10;
if(mayor<d){
mayor=d;
}
}
}
cout<<"El digito mayor es : "<<mayor;
return 0;
}
#include<iostream>
using namespace std ;
int main(){
int numero,i,d,mayor;
i=0;
cout<<"Ingrese numero :"<<endl;
cin>>numero;
while(numero>0){
if(i==0){
d=numero%10;
mayor=d;
numero=numero/10;
i++;
}else{
d=numero%10;
numero=numero/10;
if(mayor<d){
mayor=d;
}
}
}
cout<<"El digito mayor es : "<<mayor;
return 0;
}
graciaas
ResponderBorrar