C program that calculate the rate of change and indicate if it is increasing or decreasing
Posted by Samath
Last Updated: June 03, 2015

Write a C program that receives as input 4 parameters named x1 ,x2, y1 ,y2 representing continuous points of a linear equation(f(x)=x*m+b). Calculate the rate of change and also indicate if it is increasing or decreasing.

Solution:

#include<stdio.h>
#include<conio.h>
int main(int argc, char *argv[])
{

int x1,x2,y1,y2;
float ans;

printf("Enter first X parameter:"); 
scanf("%d",&x1);

printf("Enter corresponding Y parameter:");
scanf("%d",&y1);

printf("Enter second X parameter:");
scanf("%d",&x2);

printf("Enter corresponding Y parameter:");
scanf("%d",&y2);

ans = (y2-y1)/(x2-x1); 

printf("The rate of change is:%f \n",ans); 

if(ans > 0)
{
	printf("The equation is increasing. \n");
}
else if(ans < 0)
{
	printf("The equation is decreasing. \n");
}
else if (ans == 0) 
{
	printf("The equation is not changing. \n");
}

return 0;
}