Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
main ()
{
float X,Y,Z;
float rsltA = 0;
float rsltB = 0;
float rsltC= 0;
int i=0;
char str[10];
char choice;
do
{
printf("Enter real number X: ");
scanf("%f",&X);
printf("Enter real number Y: ");
scanf("%f",&Y);
printf("Enter real number Z: ");
scanf("%f",&Z);
//while (scanf("%f%f%f", &X,&Y,&Z) != 1)
//{
fgets(str,sizeof(str),stdin);
while(i<strlen(str))
{
if(str[i]<48||str[i]>57)
{
printf("Entered value contained alphabet/symbol\n");
getchar();
return 0;
}
else
{
//display the value for X,Y and Z
printf("X=%.4f ; Y=%.4f ; Z=%.4f\n", X, Y, Z );
//mathematic equations
rsltA= (5*powf(X, 2)+(3*Y))*((4*X)-(5*Y));
rsltB= logf(Z)/powf((2-logf(X)),2);
rsltC= ((4*rsltA)+(3*rsltB))/(powf(rsltB,2));
//condition for X,Y and Z
if (X==0 && Z==0)
{
printf("Function g(x,z) is not defined at x=0.0000, z=0.0000\n");
printf("f(x,y): %.4f; ",rsltA);
printf("g(x,z):#INF; ");
printf("g(x,y,z):#UNDEF\n");
printf("Do you want to continue Y/N: ");
scanf(" %c", &choice);
}
if (X<0 && Z<0)
{
printf("Function g(x,z) is not defined at x=%.4f, z=%.4f\n",X,Z);
printf("f(x,y): %.4f; ",rsltA);
printf("g(x,z):#INF; ");
printf("g(x,y,z):#UNDEF\n");
printf("Do you want to continue Y/N: ");
scanf(" %c", &choice);
}
if ((X < 0 )||(X == 0))
{
printf("Function g(x,z) is not defined at x=%.4f\n",X);
printf("f(x,y): %.4f; ",rsltA);
printf("g(x,z):#INF; ");
printf("g(x,y,z):#UNDEF\n");
printf("Do you want to continue Y/N: ");
scanf(" %c", &choice);
}
/*
if (X+=0.01)
{
printf("Function g(x,z) is not defined at x=0.0100\n");
}
if ((X += 0.01) && (Z <= 0))
{
printf("Function g(x,z) is not defined at x=0.0100, z=%.4f\n",Z);
}
if ((X += 0.01) && Z > 0)
{
printf("Function g(x,z) is not defined at x=0.0100\n");
}*/
if ((Z < 0 )||(Z == 0))
{
printf("Function g(x,z) is not defined at z=%.4f\n",Z);
printf("f(x,y): %.4f; ",rsltA);
printf("g(x,z):#INF; ");
printf("g(x,y,z):#UNDEF\n");
printf("Do you want to continue Y/N: ");
scanf(" %c", &choice);
}
else
{
printf("f(x,y): %.4f; ", rsltA);
printf("g(x,z): %.4f; ", rsltB);
printf("h(x,y,z): %.4f \n", rsltC);
printf("Do you want to continue Y/N: ");
scanf(" %c", &choice);
}
}i++;
//}
}
}while(choice=='Y'|| choice=='y');
printf("Thanks you");
}