C Program Compare, Find Quotient, Remainder and Inclusiveness of Two Numbers

Write a C program to accept two numbers and check if they are equal, to find out which is less and which is greater number. This C program also finds the quotient and remainder after dividing X by Y. It also accept a third number and checks if it is in between X and Y.

C Program to Perform Different Operations on Two Numbers

/* Aim: Accept two numbers in variables x and y from the user and perfom different operations */

#include<stdio.h>

void main()
{ 
	int X,Y,Q,R,N,t,choice;

	printf("\n Please enter two numbers:");
	scanf("%d%d",&X,&Y);
  
	printf("\n Please make a choice from the following :");
	printf("\n \n Options:\t \t \t \t"); 
	printf("Actions:");
	printf("\n \n 1. Equality :");
	printf("\t \t \tCheck if X is equal to Y");
	printf("\n \n 2. Less Than");
	printf("\t \t \tCheck if X is less tha Y");
	printf("\n \n 3. Quotient and Remainder");
	printf("\tDivide X by Y and dispaly the quotient and remainder");
	printf("\n \n 4. Range");
	printf("\t \t \tAccept the number and check if it lies between X and Y (Both Inclusive)");
	printf("\n \n 5. Swap");
	printf("\t \t \tInterchange X adn Y \n \n "); 
	scanf("%d",&choice);

	switch(choice)
	{ 
	case 1:
	if (X==Y)
		printf("\n X is equal to Y \n \n");
	else
		printf("\n X is not equal to Y \n \n");
	break;

	case 2:
	if (X<Y)
		printf("\n X is less than Y \n \n");
	else
		printf("\n X is not less than Y \n \n");
	break;

	case 3:
	Q=X/Y;
	R=X%Y;
	printf("\n The quotient and remainder is %d and %d respectively \n \n",Q,R);
	break;

	case 4:
	printf("\n Enter a number:");
	scanf("%d",&N);
	if (X<=N && N<=Y)
		printf("\n X lies in between X and Y \n \n");
	else
		printf("\n X does not lie between X and Y \n \n");
	break;

	case 5:
	t=X;
	X=Y;
	Y=t;
	printf("\n The interchanged number with %d is %d ",t,X);
	printf("\n The interchanged number with %d is %d \n \n ",X,t);
	break;
  
	default:
	printf("\n You have invalid choice \n \n");
	}
}

Output:

 Please enter two numbers:12 14
 
 Please make a choice from the following :
 
 Options:       Actions:
 
 1. Equality :     Check if X is equal to Y
 
 2. Less Than     Check if X is less tha Y
 
 3. Quotient and Remainder  Divide X by Y and dispaly the quotient and remainder
 
 4. Range     Accept the number and check if it lies between X and Y (Both Inclusive)
 
 5. Swap     Interchange X adn Y 
 
 1

 X is not equal to Y

Comments