With monday.comâ€™s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

The program should calculate total resistance of any two resistors

in parallel (R1 and R2) whose values should be any possible combination

of integer numbers between 1 and 100. The program should analyze

the output (RT), and display R1, R2, and RT on the screen if the

equivalent resistance RT is just a whole number (without decimals).

-----------------------------------------X------------------------------------------

Formula to calculate total resistance (RT) of two parallel resistors is:

RT= 1 / ((1/R1)+(1/R2))

could someone please guide me.

in parallel (R1 and R2) whose values should be any possible combination

of integer numbers between 1 and 100. The program should analyze

the output (RT), and display R1, R2, and RT on the screen if the

equivalent resistance RT is just a whole number (without decimals).

--------------------------

Formula to calculate total resistance (RT) of two parallel resistors is:

RT= 1 / ((1/R1)+(1/R2))

could someone please guide me.

Sure.

This is an incredibly easy program. Since it is obviously homework we're very limited in what we can do for you. Do you have any specific questions?

Kent

Is there some C statement that dos something like this? Could you nest two of them to do both R1 and R2?

Then you need to calculate the answer. Is there some C statement that does this?

Then you have to check if the answer is a whole number. Is there some C function that returns the whole part of a number?

then you need to see if the value is equal to the function result. Is there some C operation that checks if two numbers are equal?

Then you need to print out the numember if the conditio is true. IS there some C startement that does something if a condition is truw?

Just take these steps one at a time and just might make it.

> Then you need to calculate the answer. Is there some C statement that does this?

I think this is a wrong direction, because of calculating errors.

integer ? floating values ?

2. how to name your variables ? your formula is a good tip :)

3. how can you get the input from the user (2 lines of C, or 4 lines, 2 per input variable ) ?

4. how can you simply calculate your formula in one line ?

5. how can you display the result (one line)?

print value of er.

Put these 2 statements inside a nested for loop,which will cycle thru each combination of R1 and R2.

You will have to convert that to C code.

1. R1 = 1

2. Repeat steps 3 to 12.

3. R2 = 1

4. Repeat steps 4 to 9.

5. RT = 1 / ((1/R1)+(1/R2))

6. Display R1, R2, RT.

7. Increment R2.

8. If (R2 = 101) goto step 10.

9. End of Loop1.

10. Increment R1.

11. If (R1 = 101) goto step 13.

12. End of Loop2.

13. End of program.

Hope this helps.....

-ssnkumar

#include<stdio.h>

main()

{

int R1, R2;

for(R1=1;R1<101;R1++)

{

for(R2=1;R2<101;R2++)

{

float Rt;

Rt= (R1*R2)/(R1+R2);

printf("Total resistance is: %.2f\n",Rt);

}

}

}

i am not sure how to output the values R1, R2 , Rt just when Rt is a whole number.

Loops are good,

- you should declare Rt as well.

- display values of R1,R2 as well

- display only if there are no decimals as specified in your first message.

to do that, you have a function to get the integer part....

Example of algorithm : if (a - int(a)) == 0 ...

i can suggest this code, but there are few point that are not clear. i'll ask those after posting the code

// program starts here

main()

{

int r1, r2;

float rt;

printf("\n Enter R1:");

scanf("%d", &r1);

printf("\n Enter R2:");

scanf("%d", &r2);

rt=(float)(r1*r2)/(r1+r2);

printf("r1= %d r2=%d ", r1,r2);

printf("rt= %f %d", rt);

return 0;

}

// End of program

Q) why do you need the RT value in Integer/whole number? in most of the cases the RT will be a float value (say,R1=2, R2=3 then RT=1.2 )

-vasu

This is homework.

It should teach him doing calculations on float and integers.

Is my computer out of order?

What about Yours

int R1;

for( R1 = 1 ; R1 <= 100 ; R1++)

printf("%g\n",R1 - 1 / (1/(double)R1));

tip : you declated int R1,R2;

If R1==5 and R2==2 do you think you would get R1/R2 == 2.5 ? Answer no ...

Change your types :)

or use the cast.

(float)R1 will make R1 value a float...

have u tried any further??

Hi MOKULE! I READ YOUR PROFILE. I LEARNT FROM YOUR PROFILE THAT YOU ARE ELECTRONICS ENGINEER. NICE MEATING YOU! is there any sub-group in Experts Exchange for Q&A discussions on Electronics related questions? pls let me know(i too is in electronics related field)

thanks .

-vasu

Nice to meet Yot too.

Look at Hardware | Microchips, but it is rather strongly related to PC only.

Regards

Marek

and my apologies to all experts for sounding repetitive of previous comments.

I realized that after i had posted my comment.

it looks that the asker is not in hurry :~)

by-the-way i'm having questions regarding RS232/485 communications. where can i post those questions??

-vasu

hi Mercantilum!

the link u posted is very useful. thanks

-vasu

Maybe you can post it in Hardware/Modems

See http://www.experts-exchange.com/allTopics.jsp

See http://www.experts-exchange.com/allTopics.jsp

It turned out not so incredibly easy program.

to tarabubu

My advice is: avoid any divisions. Do necessary checking only on integer numbers.

#include<stdio.h>

main()

float R1, R2, Rt;

for(R1=1;R1<=100;R1++)

{

for(R2=1;R2<=100;R2++)

{

Rt= (R1*R2)/(R1+R2);

if(Rt-(int)Rt==0)

{

printf("R1=%0.2f 2=%0.2f Total resistance is: %.2f\n",R1,R2,Rt);

}

}

}

}

I think it is ok, but ... didn't you have to use R1,R2 as integers?

Both of You are wrong

THIS CODE IS ERRONEOUS !!!. EVEN IF IT SEEMS WORKING. IT'S ONLY BY ACCIDENT.

Execute the code below and look at the results carefully .

main()

{

int R1

for( R1 = 1 ; R1 <= 100 ; R1++)

printf("R1=%d %g\n",R1, R1 - 1. / (1./(double)R1));

}

or such code

main()

{

int R1

for( R1 = 1 ; R1 <= 100 ; R1++)

if( R1==(int)(1. / (1./(double)R1)))

printf("R1\n",R1);

}

main()

{

int R1

for( R1 = 1 ; R1 <= 100 ; R1++)

if( R1==(int)(1. / (1./(double)R1)))

printf("R1=%d\n",R1);

}

Right, I didn't test the code - after a re-lecture I think

if(Rt-(float)((int)Rt)==0)

is more correct ... not tested either :)

It's hard to be cool but I'll try.

No, it is not correct either.

Did You test my example code? I think no. Please do it. Discussion will be easier.

When You do it let me know.

Regards

cool man Marek

So, why don't you close this question?

Award points to the expert whom you think gave good solution.

If you think more than one person helped you in finding the solution, then you can split the points among different experts and then close the question.

-ssnkumar

All Courses

From novice to tech pro — start learning today.

Rt=(float) (R1*R2)/(R1+R2);

//since R1 and R2 are int,the resultant is also int,so you need to cast the result of

//the division to a float to get the correct decimal values.

if(Rt-(int)Rt==0)

{

printf("R1:%d,R2:%d,Total resistance is: %.2f\n",R1,R2,Rt);

}

//Rt is a float,so casting it as an int will truncate the decimal part.

//If the difference of the float value and the int value is 0,then Rt is a whole number

Also,if you need to calculate the resistances for fractional values also,you can consider changing the datatypes of R1 and R2 to float as mercantilum has already pointed out.