Maximum and Minimum of two numbers using simple algebra
This program finds the bigger and the smaller between two numbers. In this program no comparission operator is used. neither any switch case or if else statement. Math.h library is included because it contains the abs() and sqrt() which are used in the computation of the max and min.
Description:
This program finds the maximum and minimum values by computing respective expression and stores in max and min variables.
#include<stdio.h> #include<math.h> int main() { int a,b,max,min; printf("Enter The value of A: "); scanf("%d",&a); printf("Enter The value of B: "); scanf("%d",&b); max=abs((sqrt((a*a+b*b)-(2*a*b))+(a+b))/2); min=abs((sqrt((a*a+b*b)-(2*a*b))-(a+b))/2); printf("The Max is: %d, and the Min is: %d",max,min); return 0; }
Description:
This program finds the maximum and minimum values by computing respective expression and stores in max and min variables.
Comments
Post a Comment