Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

// C code // This program will calculate the sum of 10 positive integers. #include Int main () { /* variable definition : */ int

// C code
// This program will calculate the sum of 10 positive integers.
#include
Int main ()
{
/* variable definition : */
int count, value, sum;
Double avg;
/* initialize*/
Count = 0;
Sum = 0;
Avg = 0.0;
//Loop through to input values
While (count < 10)
{
Printf(Enter a positive integer );
Scanf (%d, &value);
If (value >= 0) {
Sum = sum + value;
Count = count + 1;
}
Else {
Printf (value must be positive );
}
}
// calculate avg. need to type cast since two integers will yield an integer
Avg = (double) sum/count;
Printf(average is %1f , avg);
Return 0;
{
2. Change the c code to average 20 intergers.
3.Prepare a new test table with at least 3 distinct test cases listing input and expected output for the new code you created averaging 10 intergers.
4. What happens if you entered a value other than an integer? (For example a float or even a string). Support your experimentation with screen captures of executing the code.
5. Modify the code to allow the user to enter any number of positive integers and calculate the average. In other words, the user could enter any number of positive integers. ( Hint: you can prompt the user for how many they want to enter. Or; you could use a sentinel
Value to trigger when the user has completed entering values). Prepare a new test table with at least 3 distinct test cases listing input and expected output for the code you created. Support your experimentation with screen captures of executing the new code.
1 Comment

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Instant Reference

Authors: Gruber, Martin Gruber

2nd Edition

0782125395, 9780782125399

More Books

Students also viewed these Databases questions