954,148 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Decimal Problem In C

Hi everyone,
Some questions in my previous post is still left unanswered.
Here it is again:

How can i accept decimal numbers from STDIN and perform arithmetic operations on it in C.

How can i create a subroutine within a program, that can be called again & again at different part of a program.
THANKS :mrgreen:

Mahen
Junior Poster
144 posts since Aug 2004
Reputation Points: 10
Solved Threads: 2
 

Hi everyone,
I not very clear what you are talking about.

Receving decimal numbers???

Do you mean returning decimal numbers from a function

declare a variable as float
float a;
a = rew( ); // Is this what you mean

As for your other question

You cannot call a function within its own function.
You can declare the function externally being public or private
and call it
if there is arguments and a return value
a = gow(c,d); // Is this what you mean

if it has no arguments or any return values

gow(); //Is this what you mean

I really hope this helps you

Yours Sincerely

Richard West

freesoft_2000
Practically a Master Poster
623 posts since Jun 2004
Reputation Points: 25
Solved Threads: 10
 

For reading you use scanf() with format specifier "%f","%g","%e" or printf();
the variable tyoe is float and functions are in math.h

You need functions->read tutorials

Fili
Light Poster
34 posts since Jun 2004
Reputation Points: 16
Solved Threads: 0
 

OK, let me clear things up, suppose i want to enter 23.45 using SCANF, the program will only accept the 23 and use the .45 for the other SCANF, how can i avoid it.

Mahen
Junior Poster
144 posts since Aug 2004
Reputation Points: 10
Solved Threads: 2
 

First, avoid scanf . Second, use a floating point type to enter a floating point value.

#include <stdio.h>
  
  int main()
  {
     double number;
     fputs("Enter number: ", stdout);
     fflush(stdout);
     if ( scanf("%lf", &number) == 1)
     {
  	  printf("number = %g\n", number);
     }
     return 0;
  }
  
  /* my output
  Enter number: 23.45
  number = 23.45
  */
Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You