Classes/Fall 2024/csci218/Assignments/ohmsLaw.c

32 lines
979 B
C

/* Name: Garrett Haldrup
ohmsLaw.c
Problem: Take an input of Voltage and Resistance and calculate Current.
Certification of Authenticity:
I certify that this assignment is entirely my own work.
*/
#include <stdio.h>
int main(void){
// Program purpose output
printf("This program will take in Voltage(V) and Resistance(Ω) to calculate the Current(A)\n");
// Declare voltage and current as double, and resistance as int
double voltage, current;
int resistance;
// Scan in voltage and resistance from user
printf("Input the Voltage in Volts(V): ");
scanf("%lf", &voltage);
printf("Input the Resistance in Ohms(Ω): ");
scanf("%d", &resistance);
// Perform Ohms Law Clalculation I = V / R
current = voltage / resistance;
// Output Current from calculation
printf("Based off the Voltage(V) of %.1lfV and Resistance(Ω) of %dΩ\n", voltage, resistance);
printf("The Current(A) is: %.3lfA\n", current);
return 0;
}