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

int main(){
float x;
x=4/(4-1);
printf("%f\n", x);

}

when I try to run that on c it makes x equal to 1, i don´t understand why

StoryTeller - Unslander Monica
  • 165,132
  • 21
  • 377
  • 458
Edu Galindo
  • 165
  • 1
  • 8

1 Answers1

1

Because you are making a division between two int, so you'll obtain an int as result.

Zeb
  • 1,715
  • 22
  • 34
  • ohh so if i want to get a float as a result i have to type "(float)" and place it before the division right? – Edu Galindo Mar 01 '17 at 23:45
  • Not exactly, you need that each number is a float, for example in this way x=4.0/(4.0-1.0); – Zeb Mar 02 '17 at 23:41