Proper fraction, improper and apparent in C language

Asked

Viewed 33 times

-3

I am trying to create the following program in C: Make a program that receives 2 numbers referring to the numerator and denominator of a fraction and inform if it is a fraction of its own, improper, or apparent. But the code does not execute the line of the apparent fraction. I would like to know what I am doing wrong. Below is the code:

inserir a descrição da imagem aqui

  • Your code gets stuck in numerador >= denominador. If this is true then it goes into that if. I suggest you check first if it is apparent and at last else if ascertain whether it is improper

1 answer

1

Note that your condition for a fraction to be improper is only accurate numerador >= denominador and to be apparent this same condition must be verified beyond the condition numerador % denominado == 0, but the first condition is already analyzed in the else if above. then the code enters the first else if. To correct change the order of the checks, first check if it is apparent and then if it is improper

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
  int numerador;
  printf("Digite o numerador da fracao: ");
  scanf("%d",& numerador);

  int denominador;

  printf("Digite o denominador da fracao: ");
  scanf("%d",& denominador);

  if(numerador < denominador){
    printf("\n A fração é propria");
  }
  else if(numerador >= denominador && numerador % denominador == 0){
    printf("\n A fração é aparente");
  }
  else if(numerador >= denominador){
    printf("\n A fração é imppropria");
  }
return 0;
} 
  • I get it, it worked out here. Thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.