Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Question about C programming

Status
Not open for further replies.

km

Junior Member level 3
Joined
May 26, 2004
Messages
31
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
322
Routine of the program:-

float ftov()
{
int a;
printf("\n \nEnter number:");
scanf("%d",&a);
OUT=0.000040955*a;
printf("\n OUT=%f\n",OUT);
return OUT;
}


When a = 10000, OUT = 0.40955
But why when a = 100000, OUT gives negative value (-1.272554) instead of 4.0995:?:
 

I would like to know which is the compiler u r using.
 

hi

i think u should try the same code in microsoft VC++ compiler.
its complier problem u may be using 16 or 32 bit complier.
u may be trying this code in TC,thats y its not working
 

In line

int a;

int is a 16 bit value. The value 100000 is 0x186a0, and when you assign a = 100000 the value is truncated to 16 bits, so the variable a equals to 0x86a0. The value 0x86a0 is equal to value -31072, so you get the value (-1.272554) instead of 4.0995.

You must replace line
int a;
with
long a;

Regards, svicent
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top