Monday, 3 October 2011

03-10-2011 Usage of Logical Operators(smallest and highest number)


/*Program takes values from user and tells which one was highest and which one was smallest*/
#include<stdio.h>
#include<conio.h>
main()
{
      int num = 0, smallest=0, highest = 0, counter = 0;
      while (num != -1)
      {
            printf("Please enter the number or -1 to see results: ");
            scanf("%d",&num);
            if ((smallest >= num && num !=-1) || (counter==0))
            {
               smallest = num;
            }
            if ((highest <= num && num != -1)||(counter == 0))
            {
                 highest = num;
            }
            counter++;
      }
      printf("\nSmallest entered value is: %d \nand the highest entered value is: %d \n\nSo the range is %d",smallest,highest,(highest-smallest));
      getche();
}          
           


No comments:

Post a Comment