Advertisement
Kl43z

Contador Digitos do...while

Sep 27th, 2014
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(){
  4.    
  5.    int input=0,dig=0, n_dig=0, min=0, max=0, suma=0, temp;
  6.  
  7.    printf ("Ingrese un número entero: \n");
  8.    scanf("%d", &input);
  9.    temp=input;
  10.    do{
  11.       dig=temp%10;
  12.       n_dig++;
  13.       suma+=dig;
  14.       if (n_dig==1){
  15.          min=dig;
  16.          max=dig;
  17.       }
  18.       else {
  19.          if (dig<min){
  20.             min=dig;
  21.          }
  22.          if (dig>max){
  23.             max=dig;
  24.          }
  25.       }
  26.  
  27.       temp/=10;
  28.    }while(temp>0);
  29.    printf ("El numero %d posee las siguientes características: \n  Posee %d dígitos.\n  La suma de sus dígitos es %d\n  El dígito menor es %d\n  El dígito mayor es %d.\n", input, n_dig, suma, min, max);
  30.    return 0;  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement