elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Introducción a Git (Primera Parte)


  Mostrar Temas
Páginas: [1]
1  Programación / Programación C/C++ / Ayuda con programa en: 16 Julio 2017, 18:12 pm
Buenas. Quisiera que me ayuden con un programa que estoy haciendo. Cuando lo ejecuto me saltan varios errores:
Código:
/home/ubuntu/: In function ‘main’:
/home/ubuntu/: error: invalid operands to binary % (have ‘float’ and ‘int’)
         unidad = num % 100;
                      ^
/home/ubuntu/workspace: error: invalid operands to binary % (have ‘float’ and ‘int’)
         unidad = unidad % 10;
                         ^
/home/ubuntu/workspace/: error: invalid operands to binary % (have ‘float’ and ‘int’)
         centena = num % 100;
                       ^
/home/ubuntu/workspace: error: invalid operands to binary % (have ‘float’ and ‘int’)
         decena = num % 100;
                      ^
/home/ubuntu/workspace: error: invalid operands to binary % (have ‘float’ and ‘int’)
         decena= decena % 10;
                        ^
/home/ubuntu/workspace/: error: invalid operands to binary % (have ‘float’ and ‘int’)
         unidad = num % 10;
                      ^
/home/ubuntu/workspace/: error: invalid operands to binary % (have ‘float’ and ‘int’)
         decena = num % 10;
                      ^


El programa es el siguiente:

//Programa para ingresar un numero (ENTERO Y POSITIVO) de 3 o 2 digitos y mostrarlo invertido.

Código
  1. #include <stdio.h>
  2.  
  3. int main (void) {
  4.  
  5.    float num=0;
  6.    float unidad=0;
  7.    float decena=0;
  8.    float centena=0;
  9.    float auxiliar=0;
  10.    float numero_invertido=0;
  11.  
  12.  
  13.    printf("Ingrese un numero de 3 o 2 cifras: ");
  14.    scanf("%f", &num);
  15.    printf("\n");
  16.  
  17.    if ((num>99) && (num<1000)) {
  18.  
  19.        unidad = num % 100;
  20.        unidad = unidad % 10;
  21.        unidad = unidad * 100;
  22.  
  23.        centena = num % 100;
  24.        centena = num - centena;
  25.        centena = centena / 100;
  26.  
  27.        decena = num % 100;
  28.        auxiliar = decena;
  29.        decena= decena % 10;
  30.        decena = auxiliar - decena;
  31.  
  32.        numero_invertido = unidad + decena + centena;
  33.  
  34.        printf("El numero invertido es: %f", numero_invertido);
  35.  
  36.  
  37.    }
  38.  
  39.  
  40.     if ((num>9) && (num<100)) {
  41.  
  42.        unidad = num % 10;
  43.        unidad = unidad * 10;
  44.  
  45.        decena = num % 10;
  46.        decena = num - decena;
  47.        decena = decena / 10;
  48.  
  49.        numero_invertido = unidad + decena;
  50.  
  51.        printf("El numero invertido es : %f", numero_invertido);
  52.  
  53.  
  54.  
  55.  
  56.    }
  57.  
  58.    else {
  59.  
  60.        printf("El numero no cumple las condiciones");
  61.  
  62.  
  63.    }
  64.  
  65.    return 0;
  66.    }


· Los códigos deben ir en etiquetas GeSHi
>aquí las reglas del foro
-Engel Lex
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines