WAP- Given the values of three variables a, b and c, write a program to compute and display the value of x, where x=a/(b-c)

Execute your program for the following values
  1. a=250, b=85, c=25
  2. a=300, b=70, c=70
Comment on the output in each case

//E Balagurusamy, Programming In ANSI C,4E
//Exercise 1.8, page 21

#include <stdio.h>
#define a 300
#define b 70
#define c 70
int main(void)
{
printf("\n\n");
printf("For a=%d, b=%d, c=%d,\n",a,b,c);
printf("x is %d",a/(b-c));
printf("\n\n");
return 0;
}

In case 1, the program executes without any warnings to give the expected output.
In case 2, the compiler gives a warning that division is being performed by zero, but gives the result as if dividing by 1 or say ignoring that portion of expression altogether, which is dividing by zero.

Comments

Post a Comment

Kindly keep your comments on-topic and don't spam.