This blog is under construction

Monday, 8 July 2013

C program to calculate PI, resistance and power

Write a C program to calculate PI, resistance and power.

  #include <stdio.h>
  int main() {
        float pi, current, voltage, resistence, power;

        /* get the current and voltage value from the user */
        printf("Enter your current value: ");
        scanf("%f", &current);
        printf("Enter the voltage value:");
        scanf("%f", &voltage);

        /* calculate pi value */
        pi = 22.0 / 7.0;

        /* calculate the resistence */
        resistence = voltage / current;

        /* calculate the power value */
        power = current * resistence * resistence;

        /* print the results */
        printf("Value of pi is %f\n", pi);
        printf("Value of resistence is %.2f ohms\n", resistence);
        printf("Value of power is %.2f watts\n", power);
        return 0;

  jp@jp-VirtualBox:~/$ ./a.out
  Enter your current value: 10
  Enter the voltage value:100

  Value of pi is 3.142857
  Value of resistence is 10.00 ohms
  Value of power is 1000.00 watts

See Also:

No comments:

Post a Comment