Monday 8 July 2013

Program to find larger of two number without using relational operator , conditional operator ,if else statements in C/C++...?

I have written the simple code for this without any use of ant bitwise operator....


#include<stdio.h>
#include<iostream>
using namespace std;
int main(void)
{
    int a = 0 , b = 0 ;
    cout << "Enter two Numbers" << endl;
    scanf("%d",&a);
    scanf("%d",&b);
    int c = a - b ;
    int temp = c + abs(c);
    c = a % b ;
    switch(c)
    {
                case 0 :
                     printf(" a and b are equal \n");
                     break;
                     default:
                             switch(temp)
                             {
                                         case 0:
                                              printf(" a is smaller than b \n");
                                              break;
                                              default:
                                                      printf(" a is greater than b \n");
                             }
    }
    return 0;
}
                                                                                    By: Saurabh Bhatia


                   
                     

No comments:

Post a Comment