Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 11-09-2006, 02:15 AM   #1
Solid State Member
 
Join Date: Jun 2006
Posts: 16
Default how to code this..

Hello forum, how r u ?
Its been so long not post here,
I have a question and I hope I find the answer here
>>>>>>
Im a c programming beginner , I donít know how to code the following :
Tell me please how to compute this:



Thank you a lot.
__________________

e-girl is offline   Reply With Quote
Old 11-09-2006, 06:39 AM   #2
Site Team
 
root's Avatar
 
Join Date: Mar 2004
Posts: 8,003
Default Re: how to code this..

OK....

it's just a simple expression involving powers and square roots...

you'll need to include the Math library

Code:
#include<math.h>
the math functions work using doubles, so you'll need to define them

Code:
 
double l, c r, f;
then you'll need to get those numbers from the user, (or a file it's up to you).
Code:
printf ("enter that value of the capacitor");
scanf ("%lf", c);
printf ("enter that value of the coil");
scanf ("%lf", l);
printf ("enter that value of the resistor");
scanf ("%lf", r);
then you just need to write down the expression...

square rout in C is done like this,

result = sqrt(number);

powers are done like this

result = pow( number, power);

Code:
f = (sqrt(1/(l*c))) - sqrt((pow(r, 2)/(4*pow(c, 2)));
then output f
Code:
printf("Frequency = %lf", f);
This isn't tested fully, but I don't immediatly see any reason that it won't work...

I suspect that this is home work help,
you can hand this in if you like, but it won't recieve a great mark,

the program is not fool proof, I suggest that you look at the scanf statements, you can put anything into scan f, including multiple numbers, letters, huge numbers etc...

you should put a bit of error checking in there to complete the program properly...
__________________

__________________
I didnít fight my way to the top of the food chain to be a vegetarianÖ
Im sick of people saying 'dont waste paper'. If trees wanted to live, they'd all carry guns.
"The inherent vice of capitalism is the unequal sharing of blessings; The inherent vice of socialism is the equal sharing of miseries."
root is offline   Reply With Quote
Old 11-10-2006, 11:10 AM   #3
Solid State Member
 
Join Date: Jun 2006
Posts: 16
Default Re: how to code this..

thank you very much "root"
but i have another question and really really need help
look at this:
write a program to compute the sum of a 4 digit number.
Example :
No=2416
sum=13
.............
could you help me please?
e-girl is offline   Reply With Quote
Old 11-10-2006, 08:11 PM   #4
Daemon Poster
 
xtremezx2's Avatar
 
Join Date: Sep 2006
Posts: 915
Default Re: how to code this..

your going to have to read the number in (which will be a string) and parse each of the digits, convert them to an integer, and add them up. this one should be easy if you've been keeping up in your class because you know exactly how many digits the number would be. I'm not gonna give you the code for is because 1. my c is very rusty and the syntax escapes me, and 2. this is your homework. just think about how you read it in from the user and how you break it up. once your break it up its just addition and output. good luck, hope you figure it out.
xtremezx2 is offline   Reply With Quote
Old 11-15-2006, 11:40 AM   #5
Solid State Member
 
Join Date: Jun 2006
Posts: 16
Default Re: how to code this..

yeah
you are right
thank you so much
e-girl is offline   Reply With Quote
Reply

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 Off



All times are GMT -5. The time now is 02:17 PM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0