#include
int main (){
int x,y,z;
printf("please enter value of x");
scanf("%d",&x);
printf("please enter value of y");
scanf("%d",&y);
if (y == 0) {
printf("You can not divide by zero");}
else{
z = x / y;
printf("divide = %d \n",z);}
and also
#include
int main (){
int x,y,z;
printf("please enter value of x");
scanf("%d",&x);
printf("please enter value of y");
scanf("%d",&y);
if (y != 0) {
z = x / y;
printf("Divide = %d \n",z);
}
else{
printf("You can not divide by zero");
}

VulpesPosted Aug 15, 2012, 8:36 AM
Other than that, you might be wondering why when you enter (say) 1 for x and 4 for y, you get an answer for z of 0 rather than 0.25.
The reason is that when you divide two ints, integer arithmetic is used which means that you get the answer to the lower integer and the remainder is discarded.