This blog is under construction

Monday 8 July 2013

C program to calculate percentage

Write a C program to calculate percentage.


  #include <stdio.h>
  int main() {
        float x, y, percent;

        /* get the inputs x and y from the user */
        printf("X out of Y:\n");
        printf("Enter the value for X: ");
        scanf("%f", &x);
        printf("Enter the value for Y: ");
        scanf("%f", &y);

        /* percentage calculation */
        percent = (x * 100) / y;

        /* print the outputs */
        printf("%.2f out of %.2f is %.2f percent\n", x, y, percent);
        return 0;
  }



  Output:
  jp@jp-VirtualBox:~/$ ./a.out
  X out of Y:
  Enter the value for X: 157
  Enter the value for Y: 200
  157.00 out of 200.00 is 78.50 percent





See Also:

No comments:

Post a Comment