how to code this..

e-girl

Solid State Member
Messages
16
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:

65591859.jpg


Thank you a lot.
 
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...
 
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?
 
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.
 
Back
Top Bottom