LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Mandriva
User Name
Password
Mandriva This Forum is for the discussion of Mandriva (Mandrake) Linux.

Notices


Reply
  Search this Thread
Old 07-27-2004, 08:10 PM   #1
shams
Member
 
Registered: Jan 2004
Posts: 535

Rep: Reputation: 30
error coding a function in c


hi,
This is the code for a function:
#include <stdio.h>
main()
{
float square();
float a, b;

printf("Enter any number\n");
scanf("%f",&a);

b=square(a);
printf(" sqaure of %f is %f\n",a,b);

}
float square(float x)
{
float y;

y=x*x;
return(y);

}
and this is the error of result when run the program:
[root@localhost lbin]# ./l138
Enter any number
2.5
sqaure of 2.500000 is 0.000000
plz tell me where is the mistake.
 
Old 07-28-2004, 12:09 AM   #2
rgiggs
Member
 
Registered: Apr 2004
Location: berkeley, ca
Distribution: slk10, winxp
Posts: 313

Rep: Reputation: 30
i printf x in the function square, and it is 0, that's why the result of y = x * x = 0; then i noticed you declare float square(); change it to float square(float); it should work.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Coding a redirect function in php mrobertson Programming 2 06-22-2005 08:40 AM
error coding structure in c shams Programming 9 08-24-2004 10:02 AM
error coding string in c shams Programming 1 08-23-2004 09:01 PM
error coding string in c shams Programming 2 08-20-2004 05:44 AM
error coding a funtion in c shams Programming 2 07-27-2004 09:47 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Mandriva

All times are GMT -5. The time now is 01:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration