C Programming Tips & Tricks





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
Code Snippets
 List All
 Arrays
 Calculators
 Datatypes
 Date & Time
 File Manipulation
 Math Functions
 Multimedia
 Others
 




Calculate Electric Power - C

Snippets  C  Calculate Electric Power
Snippet On
Electric Power




Code
  
Rate this page :
  [ 0 votes]


#include <stdio.h>
int main()
{
float power,voltage,current;
voltage = current = 0;
printf(<q>Power calculator.\n</q>);
printf(<q>This will calculate the power in watts </q>);
printf(<q>when you input the voltage and current.</q>);
/*get the voltage*/
printf(<q>Enter the voltage in volts.\n</q>);
scanf(<q>%f</q>,&voltage);
/*get the current*/
printf(<q>Enter the current in &s.\n</q>);
scanf(<q>%f</q>,¤t);
/*calculate the power*/
power = voltage * current;
printf(<q>The power in watts is %.2f watts\n</q>,power);
return 0;
}

Output:
======
Electric Power Calculation:-This will calculate the power in watts,when you input the voltage and current.
Enter the voltage in volts : 240
Enter the current in &s : 5
The power in watts is : 1200 watts




Other Links

web hosting