A program that finds the largest in a series of numbers entered by the user. The program must prompt the user to enter numbers one by one. When the user enters 0 or a negative number, the program must display the largest non negative number entered. Note that the numbers aren't necessarily integers.

PHOTO EMBED

Mon Oct 07 2024 23:05:18 GMT+0000 (Coordinated Universal Time)

Saved by @khadizasultana #c #loop #conditionals

#include<stdio.h>
// Author- Khadiza Sultana
// 10/8/2024
//Finding the largest number with the help of loop
int main()
{
    double number = 0, largest = 0; // initialization is done
    for(;;)
    {
        printf("Enter the number:");
        scanf("%lf", &number);
       
        if(number <= 0)
           break; // when zero or negative number then the infinite loop is broke

        if(number > largest)
           largest = number; // storing the largest number after comparing
    }
    printf("\nThe largest number is %g\n", largest);
   
    return 0;
}
content_copyCOPY

I found this question from Program project of chapter 6 of the book A modern approach to C by K.N King