When i run this program it show me unlimited number of same ans.
But The ans are correct.
so, how can i avoid this problem. thanks.
Code:
/*Write a program that will finds the largest in a series ofnumbers entered by the user. The program must prompt the
user to enter one by one. When the user enters 0 ,
the program must display the largest nonnegative number entered:
*/
//CREATED BY: ABHIJIT DAS
//DATE:1.7.2012
//VER: 1.0
#include<stdio.h>
#include<conio.h>
main()
{
float a, b, c;
printf("Enter a number:\n");
scanf("%f", &a);
while(a == 0)
{
printf("You must enter a number. Please enter a number\n");
scanf("%f", &a);
}
if(a != 0)
{
c = +a;
}
printf("Enter a number:\n");
scanf("%f", &b);
if(b == 0)
{
printf("The largest number is %f\n", c);
}
while(a> 0 && b>0)
{
if(b!= 0 && b>c)
{
c = +b;
}
printf("Enter a number:\n");
scanf("%f", &a);
while(a == 0)
{
printf("The largest number is :%f", c);
}
if(a != 0 && a>c)
{
c = +a;
}
printf("Enter a number:\n");
scanf("%f", &b);
}
while(a == 0 || b == 0)
{
printf("The largest number is %f\n", c);
}
getch();
return 0;
}