Computer Programming C Laboratory: Functions C Programs

C Program to calculate the ratio for the given x,y,z values

Programs Using Functions - C Programming

Calculate the ratio for the given x,y,z values using x/(y‒z).

* C Program to calculate the ratio for the given x,y,z values */

#include <stdio.h>

#include <conio.h>

{

main()

/* Local definition */

int x,y,z,

float ratio (int, int, int);

/* Statements */

printf("Enter x,y,z values.....");

scanf("%d %d %d", &x, &y, &z);

printf("Ratio is..... %f\n", ratio(x,y,z));

} /* main */

float ratio(int x, int y, int z) /* ratio() is a function with arguments */

{

int diff(int, int);

if(diff(y,z))

          return(x/(y‒z));

else

          return(0);

} /* ratio() */

diff(int m,int n) /* diff() is a function with arguments */

{

if(m!=n)

      return(1);

else

       return(0);

} /* diff() */

OUTPUT

Enter x,y,z values... 10 10 5

Ratio is..... 2.000000

EXPLANATION: In the program the main function reads the values for x, y, z and calls the ratio() function to calculate x/(y‒z). The ratio can not be evaluated if (y‒z)=0, then the ratio function calls another function called diff() to find the difference between (y‒z) is zero or not.


Computer Programming C Laboratory: Functions C Programs : Tag: C Programming : - C Program to calculate the ratio for the given x,y,z values


Computer Programming C Laboratory: Functions C Programs



Under Subject



Related Subjects