in c please?

2021-02-26 3:10 am
Write a program to perform calculations on three user floating-point numbers between 0 and 100 inclusive and print the results with different formatting.

• Prompt the user to "Enter 3 floating-point numbers between 0 and 100 inclusive: "
• If the data is outside that range, print "THE DATA IS INVALID!". Otherwise, do the following calculations:
• Print "Average using scientific notation: " followed by the correct number.
• Print "Square root of the average to eight decimal places: " followed by the correct number.
• Print "Rounded average: " followed by the correct number.
• Print "Integer average: " followed by the correct number whether it's odd or even in parenthesis.
A sample run with three good numbers:
Enter 3 floating-point numbers between 0 and 100 inclusive:
23.456789
45.6789
67.89
Average using scientific notation: 4.567523e+01
Square root of the average to eight decimal places: 6.75834519
Rounded average: 46
Integer average: 45 (odd)

回答 (3)

2021-02-27 4:43 am
yes you should definitely be able to do this very basic thing, if you expect to be a programmer, which requires much more complicated problems to be solved...
2021-02-28 12:12 am
You can split this up.  The first is the input, you can use the sscanf fscanf routines, they can validate the data for you.

For the calc, just take the example and put them in 3 variables and figure out the calc and format..

Put the 2 together, there you go.
2021-02-26 3:57 am
declare an array of floats to hold the three numbers.

while you have less than three numbers { get input, if the input is good store it and increment the index else complain }

calculate and print each result.


收錄日期: 2021-04-24 08:34:23
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20210225191024AAmggQT

檢視 Wayback Machine 備份