0% found this document useful (0 votes)
36 views1 page

C Programming

The document provides a C programming problem to write a program that finds the largest number entered by a user among a series of numbers. The user is prompted to enter numbers one by one until entering a 0 or negative number, at which point the program displays the largest non-negative number. The solution uses a do-while loop to repeatedly prompt for a number, compare it to the current largest number stored in a variable, and update the largest number if needed, until the entered number is 0.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views1 page

C Programming

The document provides a C programming problem to write a program that finds the largest number entered by a user among a series of numbers. The user is prompted to enter numbers one by one until entering a 0 or negative number, at which point the program displays the largest non-negative number. The solution uses a do-while loop to repeatedly prompt for a number, compare it to the current largest number stored in a variable, and update the largest number if needed, until the entered number is 0.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

C Programming

C PROGRAMMING

Problem:
Write 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 negative
number, the program must display the largest nonnegative number entered:

Enter a number: 10
Enter a number: 32.3
Enter a number: 4.32
Enter a number: 142.61
Enter a number: 95.2795
Enter a number: 30
Enter a number: 0

The largest number entered was 142.61

Solution:
#include <stdio.h>

int main()
{

float n,x;
x=0;
do
{
printf("Enter a number: ");
scanf ("%f", &n);
if (n>x)
{
x=n;
}

}
while (n!=0);
printf("The largest number entered was:%.4f \n", x);

getch();
}

©Nandraj Kisto

You might also like