Forum     

Go Back   Digit Technology Discussion Forum > Portables, Peripherals and Electronics > QnA (read only)
Register FAQ Calendar Mark Forums Read

QnA (read only) Mods please help transfer the contents of this forum to proper sections. :)


 
 
LinkBack Thread Tools Search this Thread Display Modes
Old 29-07-2005, 03:16 PM   #1 (permalink)
In The Zone
 
tweety_bird_bunny's Avatar
 
Join Date: Oct 2003
Posts: 211
Default plz see the "C" coding.tel watz wrong?


i did following coding in devc++ ver4..... it is taken from kanetkar's Let Us See book....... but it doesn't seem to work....it should recieve a float value & return its square.... no matter what i enter it gives its square as 0.000000.....
whats going wrong any suggestions.......
if it works fine on ur sys plz tel me ur compiler name....


main()
{
float square();
float a,b;
printf("plz enter the float number\n");
scanf("\n%f",&a);
b=square(a);
printf("\nsquare is %f",b);


}
float square(float x)
{
float y;
y=x*x;
return(y);
}
tweety_bird_bunny is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 29-07-2005, 03:31 PM   #2 (permalink)
Wise Old Owl
 
siriusb's Avatar
 
Join Date: May 2005
Location: Chennai, India, Asia, the Earth, the Solar system, the Milky Way, the Local group, this Universe.
Posts: 1,171
Default

The code shud work. But there are a few modifications that I would suggest.
Put the square function above the main function or use a function declaration above main.
__________________
http://myxp.blogspot.com
-----------------------
Winchester 3200+ @2,500MHz
LeadTek 7900GT VOLT MODDED @ 680 core, 1800 mem
2x1GB Transcend DDR400 @ DDR454 2.5,3,3,5,1T
siriusb is offline  
Old 29-07-2005, 04:04 PM   #3 (permalink)
In The Zone
 
Thor's Avatar
 
Join Date: Jun 2004
Location: Kolkata
Posts: 384
Default C problrm solved

Did u include stdio.h ??
Code:
#inclue<stdio.h>
=====================
Code:
 b=square(a)
for the abv code to work float square();
must become
Code:
float square(float);
Now
the complete program :
Code:
#include<stdio.h>
#include<conio.h>
main()
{
float square(float);
float a,b;
printf("plz enter the float number\n");
scanf("\n%f",&a);
b=square(a);
printf("\nsquare is %f",b);
getch();
}
float square(float x)
{
float y;
y=x*x;
return(y);
}
IMPORTANT : I had to put
Code:
#include<conio.h>
and
Code:
getch();
because I use Borland C++ , without it the output screen blinks out in a ziffy and doesn't allow me to see the output. If u use DOS v compiler u can do without those 2 lines of Code too.
__________________
Beware of my Wrath Mortals, Thou hast no choice.
Thor is offline  
Old 29-07-2005, 05:03 PM   #4 (permalink)
Wise Old Owl
 
deathvirus_me's Avatar
 
Join Date: May 2005
Location: Kolkata, India
Posts: 1,838
Default

The float() function is declared as
float square();

Thats a no argument function .... it will only return a value ..

U've now defined the function as
float square(float x)

So even if u pass a value to the function x will be zero because u've declared the function differently ...

It should be declared as float square(float)


here's the complete program :

Code:
#include <stdio.h>
#include <conio.h>
main()
{
   float square(float);
   float a;
   clrscr();
   printf("plz enter the number :");
   scanf("%f",&a);
   printf("\n\n Square is %f",square(a));
   return 0;
}
float square(float x)
{
   return(x*x);
}
deathvirus_me is offline  
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by Krow
- by abhidev
- by topgear
- by clmlbx

Advertisement




All times are GMT +5.5. The time now is 07:02 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2