Click here to Skip to main content
15,884,353 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
COULAMB LAW FORMULAS BASED QUESTIONS SOLUTION IN C PROGRAMMING
CREATW A PROGRAM N C \

Q1=2COULAMB
Q2=4COLAMB
R=6
K=1/4*pi*ePSILON0
IN BASIC PROGRAM BECAUSE I AM BEGINER

What I have tried:

#include<stdio.h>
/* #define PI 3.14
#define Epsilon0 8.85E-12
*/
int main()
{ 
  float q1,q2,r,F;
  printf("enter q1 charge:");
  scanf("%f",&q1);
  printf("\nenter q2 charge:");
  scanf("%f",&q2);
  printf("\nenter the r value:");
  scanf("%f",&r);
  const double k=9000000000;
  printf("\nk for constant is %lf",k);
  F= (k*q1*q2)/(r*r);
  printf("\ncoloumb force is %f",F);
  return 0;
}
Posted
Updated 8-May-22 8:26am
v2
Comments
0x01AA 8-May-22 10:51am    
And the question is?
If in doubt, read this: Coulomb's law - Wikipedia[^]

And btw: r seems to be undefined?
Graeme_Grant 8-May-22 10:53am    
Ah, homework question ...
Patrice T 8-May-22 11:52am    
and you have a question or problem ?

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 
The code you posted is basically correct. I suggest you some minor changes
C
#include <math.h>
#include <stdio.h>

int main()
{
  const double EPS0 = 8.85418782E-12;

  const double K = 1/(4*M_PI*EPS0);

  double q1, q2, r, f;

  printf("enter q1 charge (C): ");
  scanf("%lf",&q1);
  printf("\nenter q2 charge (C): ");
  scanf("%lf",&q2);
  printf("\nenter the r value (m): ");
  scanf("%lf",&r);

  printf("\nk for constant is %f N * m^2 * C^-2\n", K);
  f = (K*q1*q2/r*r);
  printf("\nColoumb force is %g\n",f);

  return 0;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900