Arduino Aficionado
Created May 11, 2015

Electricity Basic's

Intro to Electronic's/Arduino

BeginnerFull instructions provided106
Electricity Basic's

Story

Read more

Code

Ohm's Law

C/C++
To find Ohm's Law
#include<stdio.h>

#include<conio.h>

#include<stdlib.h>

 

#define PI 3.14

 

int main(){



char ch;

float voltage , resistance , current , result;

 

printf("Ohms law calculator.\n");

printf("Please choose from following calculcations.\n");

printf("1. choose 1 to calculate the voltage.\n");

printf("2. choose 2 to calculate the current.\n");

printf("3. choose 3 to calculate the resistance.\n");

printf("Anything else to quit.\n");

 

scanf("%c",&ch);

switch(ch)
{

case '1' :

printf("please enter the current in amps.\n");

scanf("%f",&current);

printf("Now enter the resistance in ohms.\n");

scanf("%f",&resistance);

result = current * resistance;

printf("The voltage is %0.2f volts.\n",result);

break;

case '2' :

printf("please enter the voltage in volts.\n");

scanf("%f",&voltage);

printf("Now enter the resistance in ohms.\n");

scanf("%f",&resistance);

result = voltage / resistance;

printf("The current is %0.2f amps.\n",result);

break;

case '3' :

printf("please enter the voltage in volts.\n");

scanf("%f",&voltage);

printf("Now enter the current in amps.\n");

scanf("%f",&current);

result = voltage / current;

printf("The resistance is %0.2f ohms.\n",result);

break;

default :

exit(0);

break;

 
}

return 0;

}

Credits

Arduino Aficionado

Arduino Aficionado

2 projects • 9 followers
Hacker, Maker, Tinkerer,Optimist
Thanks to Maker's Square.

Comments