Code:
/* Write a program to find the range of a set of numbers. Range
is the difference between the smallest and biggest number in
the list
Date : 16/07/2016 Time : 6.51 PM IST */
#include<stdio.h>
int main()
{
int num_1;
int max_num=0;
int min_num=0;
char choice ='Y';
printf("Enter a number : ");
scanf("%d", &num_1);
if(choice == 'Y')
{
if(num_1 >= max_num)
{
max_num = num_1;
}
else min_num = num_1;
printf("Do you want to enter a new number? ( Y/N ):");
scanf(" %c",&choice);
}
printf(" \n Max Number : %d | Min Number : %d | Difference : %d", max_num,min_num,max_num-min_num);
return 0;
}
The output is not what I had expected:
The loop is terminating prematurely. Where am I going wrong I wonder..
Please help. Thanks in advance