SlideShare a Scribd company logo
// C code
// This program will calculate the sum of 10 positive integers.
// Developer: Faculty CMIS102
// Date: Jan 31, XXXX
#include <stdio.h>
#include <stdbool.h> // needed for the Boolean variable
debug.
int main ()
{
/* variable definition: */
int count, value, sum;
int err;
float avg;
bool debug;
/* Initialize */
count = 0;
sum = 0;
avg = 0.0;
debug = false;
// Loop through to input values
while (count < 10)
{
printf("Enter a positive Integern");
err = scanf("%d", &value);
if (debug) printf(" err = %dn",err);
if (debug) printf(" value is %dn " , value ); //note the
value of debug
if (value >= 0) {
sum = sum + value;
count = count + 1;
}
else {
printf("Value must be positiven");
}
}
// Calculate avg.
// Since sum and count are both integers, this will give you an
integer division
// Hence, we need to either
// Declare sum as a float or...
// type cast sum as float (as shown below)
avg = (float) sum/count;
printf("sum is %dn", sum);
printf("average is %fn " , avg );
return 0;
}
Week 4 Classroom Lecture
This week, the new pseudo commands are the Loops (or
Repetitive) statements: A Repetitive
(or Loop) statement is how you would execute the same block
of code multiple times until some
exit condition is met.
There three types of Loops statements that we will learn. A
Loop may be one of two types – pre
test or post test. In a pre-test loop, the conditional test must be
True before the code enters the
loop. In a post-test loop, the code enters the loop first and then
the conditional test is performed
at the end of the loop to determine whether to exit or not.
The three Loop statements are:
at least once
Until (condition is true) - post test – if condition is True, the
code exits the loop
- pre test – if the condition is True,
the code enters the loop
est is an enter conditional
End While
-pre test – if the
condition is True, the code
enters the loop
– you can use constant, a variable, or an
expression
– the increment is done at the end of the
loop
End For
NOTE: The module readings has the pseudo-code for a For loop
as For i = 1 step 1 to n
We will NOT use this nomenclature.
NOTE: The module readings also has Input statement without a
prompt (Write) to the
user as to what to enter. This bad practice as the user will be
sitting there and not know
that he is supposed to enter something. Your Input statements
should always be
preceded by a prompt (i.e. Write statement) to the user.
-controlled loop
o a special value is used to exit the loop
o this value is typically an invalid or illogical value such as -1
for a value that is typically
positive like age or cost
and is typically entered by the user to exit a loop
– occurs when your test conditional is never
met. Always, check your test
condition carefully.
-controlled loops
o the counter is usually an Integer
o Initialize the counter
o Increment/Decrement the counter
Example for each of the types of loops: Sum of integers from 1
to 10
Set J, sumJ = 0 //Always initialize your counter and variables
Repeat
Set J = J + 1 //Increment the counter
Set sumJ = sumJ + J // Add the current value of J to the sumJ
variable
Until (J == 10) //When J equals 10, the loop exits
Write (“sumJ is: “ + sumJ) //sumJ is: 55
Set J, sumJ = 0 //Always initialize your counter and variables
While (J < 10) //Enters the loop if J is less than 10
Set J = J + 1 //Increment the counter
Set sumJ = sumJ + J // Add the current value of J to the sumJ
variable
End While
Write (“sumJ is: “ + sumJ) //sumJ is: 55
// OR if you start with 1 … Notice the logic is slightly
different….
Set J = 1
Set sumJ = 0 //Always initialize your counter and variables
While (J <= 10) //Enters the loop if J is less than or equal to
10
Set sumJ = sumJ + J // Add the current value of J to the sumJ
variable
Set J = J + 1 //Increment the counter
End While
Write (“sumJ is: “ + sumJ) //sumJ is: 55
Set sumJ = 0 //Always initialize your counter and variables
For (J=1; J <= 10; J++) //J is initialized to 1, Enters the loop if
J is less than or equal to 10
Set sumJ = sumJ + J // Add the current value of J to the sumJ
variable
End While // J is incremented by 1 (i.e. J++)
Write (“sumJ is: “ + sumJ) //sumJ is: 55
Example: Sentinel-controlled loop
Set count, ageSum, avgAge = 0 // Initialize to 0
Set age = 1 //Always initialize your variables- need to set age to
1, so that it enters the loop
While (age > 0) //Enters the loop if age is greater than 0
Write (“Please enter your age, enter -1 to exit”) //Prompt the
user to enter age or -1 to exit
Input age //get the user input
If (age > 0) then //test the value of age, if greater than 0,
then process your code
Set count = count + 1 // increment loop counter, only if
valid age
Set ageSum = ageSum + age //accumulate the sum of the
ages
Endif
End While
//Calculate the average age
Set avgAge = ageSum / count //Calculate the average age
Example: Sentinel-controlled loop using a Boolean
Declare continueEntry AS Boolean
Declare count, age AS Integer
Declare ageSum, avgAge AS Float //Declare ageSum as Float
to avoid Integer division
Set continueEntry = True // need to set to True, so that it enters
the loop
Set count, ageSum, avgAge = 0 // Initialize to 0
Set age = 0 //Always initialize your variables
While (continueEntry) //Enters the loop if age is greater than 0
Write (“Please enter your age, enter -1 to exit”) //Prompt the
user to enter age or -1 to exit
Input age //get the user input
If (age > 0) then //test the value of age, if greater than 0,
then process your code
Set count = count + 1 // increment loop counter, only if
valid age
Set ageSum = ageSum + age //accumulate the sum of the
ages
Set continueEntry = True
Else
Set continueEntry = False //set Boolean to False to exit
the loop
Endif
End While
//Calculate the average age
If (count > 0) //Test count so that we
don’t have division by 0
Set avgAge = ageSum / count //Calculate the average age
Endif
1
CMIS 102 Hands-On Lab
// Week 4
Overview:
This hands-on lab allows you to follow and experiment with the
critical steps of developing a program including the
program description, Analysis, , Design(program design,
pseudocode), Test Plan, and implementation with C code. The
example provided uses sequential, repetition statements and
nested repetition statements.
Program Description:
This program will calculate the average of 10 positive integers.
The program will ask the user to 10 integers. If any of the
values entered is negative, a message will be displayed asking
the user to enter a value greater than 0. The program will
use a loop to input the data.
Analysis:
I will use sequential, selection and repetition programming
statements.
The program will loop for 10 positive numbers, prompting the
user to enter a number.
I will define three integer variables: count, value and sum.
count will store how many times values greater than 0 are
entered. value will store the input. Sum will store the sum of all
10 integers.
I will define one double number: avg. avg will store the average
of the ten positive integers input.
The sum will be calculated by this formula: sum = sum + value
For example, if the first value entered was 4 and second was 10:
sum = sum + value = 0 + 4
sum = 4 + 10 = 14
Values and sum can be input and calculated within a repetition
loop:
while count <10
Input value
sum = sum + value
End while
Avg can be calculated by:
avg = value/count
A selection statement can be used inside the loop to make sure
the input value is positive.
If value >= 0 then
count = count + 1
sum = sum + value
Else
input value
End If
2
Program Design:
Main
// This program will calculate the average of 10 integer numbers
// Declare variables
// Initialize variables
// Loop through 10 numbers
// Prompt for positive integer
// Get input
// test input value for gt 0
if (value > 0)
//Increment counter
//Accumulate sum
Else
// display msg to enter a positive integer
// Prompt for positive integer
// Get input
Endif
// End loop
//Calculate average
//Print the results (average)
End
Test Plan:
To verify this program is working properly the input values
could be used for testing:
Test Case Input Expected Output
1 1 1 1 0 1
2 0 1 3 2
Average = 1.2
2 100 100 100 100 -100
100 200 -200 200 200
200 200
Input a positive value
Input a positive value
average is 120.0
NOTE: test #2 has 12 input numbers because there are two
negative numbers.
3
Pseudocode:
Main
// This program will calculate the average of 10 positive
integers.
// Declare variables
Declare count, value, sum as Integer
Declare avg as double
//Initialize values
Set count=0
Set sum = 0
Set avg = 0.0;
// Loop through 10 integers
While count < 10
Print “Enter a Positive Integer”
Input value
If (value >=0)
sum = sum + value
count=count+1
Else
Print (“*** Value must be positive ***”)
Print “Enter a Positive Integer”
Input value
End if
End While
// Calculate average
avg = sum/count
// Print results
Print “Average is “ + avg
End //End of Main
4
C Code
The following is the C Code that will compile in execute in the
online compilers.
#include <stdio.h>
#include <stdbool.h> // needed for the Boolean variable
debug.
int main ()
{
/* variable definition: */
int count, value, sum;
int err;
float avg;
bool debug;
/* Initialize */
count = 0;
sum = 0;
avg = 0.0;
debug = false;
// Loop through to input values
while (count < 10)
{
printf("Enter a positive Integern");
err = scanf("%d", &value); //note: err is the error code
returned by scanf.
if (debug) printf(" value is %dn " , value ); //note the
value of debug
if (debug) printf(" err = %dn",err); // note: err is the error
code returned by scanf.
if (value >= 0) {
sum = sum + value;
count = count + 1;
}
else {
printf("Value must be positiven");
}
}
// Calculate avg.
// Since sum and count are both integers, this will give you an
integer division
// Hence, we need to either
// Declare sum as a float or...
// type cast sum as float (as shown below)
avg = (float) sum/count;
printf("sum is %dn", sum);
printf("average is %fn " , avg );
return 0;
5
}
Setting up the code and the input parameters in ideone.com:
Note the input integer values are 1, 1, 1, 0, 1, 2, 0, 1, 3, 2 for
this test case.
You can change these values to any valid integer values to
match your test cases.
You should also test with a negative number to make sure the
positive integer logic works properly.
Note: the input data needs to be entered into the stdin window
separated by a space of new line.
6
Results from running the programming at ideone.com:
7
Learning Exercises for you to try:
8
1. Change the code to average 20 integers as opposed to 10.
Support your experimentation with screen captures
of executing the new code. What happens if you change the
formatter to %.2f printf("average is %.2fn " ,
avg );
2. 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. To
help in your analysis try as input 1 2 3 a 4 5
Hint: activate this line if(debug) printf(" value is %dn " ,
value ); after the scanf statement that reads in the
value. Activate by changing the value of debug.
Next try as input 1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9 10.5
What happens?
3. Modify the code to allow the user to enter an unspecified
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). You may need to conduct some research on your own to
solve this problem.
4. 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.
Submission
Submit a neatly organized word (or PDF) document that
demonstrates you successfully executed this lab on
your machine using an online compiler. You should provide a
screen capture of the resulting output.
Also, provide the answers, associated screen captures, C Code
and descriptions of your successful completion
of learning exercises 1, 2, 3 and 4.
The answers to the learning exercises, screen captures, C code
and descriptions can be included in the same
neatly organized document you prepared as you ran this lab.
Note the code can be embedded in the word
document. However; be sure all code compiles and runs
perfectly before submitting the document.
Submit the C-code for no. 3 as a separate .txt (or .c ) file.
Submit your document no later than the due date listed in the
syllabus or calendar.
Grading guidelines
Submission points
No. 1 Successfully demonstrates execution of this lab with
online compiler for
exercise no. 1. Includes a screen capture of executing the new
code.
2
No. 2 Describes what happens if you entered a value other than
an integer? Support
your experimentation with screen captures of executing the
code.
2
No. 3 Modifies the C code to allow the user to enter an
unspecified number of
positive integers and calculate the average. Submit C code (as .c
or .txt) file screen
captures of executing the code.
3
No. 4 Provides a new test table with at least 3 distinct test
cases listing input and
expected output your program. Should include at least one
negative value.
2
Document is well-organized, and contains minimal spelling and
grammatical errors. 1
Total 10
9

More Related Content

Similar to C code This program will calculate the sum of 10 positive .docx

C++ loop
C++ loop C++ loop
C++ loop
Khelan Ameen
 
Programming egs
Programming egs Programming egs
Programming egs
Dr.Subha Krishna
 
C++ TUTORIAL 2
C++ TUTORIAL 2C++ TUTORIAL 2
C++ TUTORIAL 2
Farhan Ab Rahman
 
Java căn bản - Chapter6
Java căn bản - Chapter6Java căn bản - Chapter6
Java căn bản - Chapter6Vince Vo
 
Advanced Computer Programming..pptx
Advanced Computer Programming..pptxAdvanced Computer Programming..pptx
Advanced Computer Programming..pptx
KrishanthaRanaweera1
 
Loop and while Loop
Loop and while LoopLoop and while Loop
Loop and while Loop
JayBhavsar68
 
Chap 4 c++
Chap 4 c++Chap 4 c++
3.2 looping statement
3.2 looping statement3.2 looping statement
3.2 looping statement
PhD Research Scholar
 
Python programing
Python programingPython programing
Python programing
hamzagame
 
Chapter 5 exercises Balagurusamy Programming ANSI in c
Chapter 5 exercises Balagurusamy Programming ANSI  in cChapter 5 exercises Balagurusamy Programming ANSI  in c
Chapter 5 exercises Balagurusamy Programming ANSI in c
BUBT
 
Control structure of c
Control structure of cControl structure of c
Control structure of c
Komal Kotak
 
Lec7 - Loops updated.pptx
Lec7 - Loops updated.pptxLec7 - Loops updated.pptx
Lec7 - Loops updated.pptx
NaumanRasheed11
 
Python Training in Chandigarh(Mohali)
Python Training in Chandigarh(Mohali)Python Training in Chandigarh(Mohali)
Python Training in Chandigarh(Mohali)
ExcellenceAcadmy
 
Python Training Course in Chandigarh(Mohali)
Python Training Course in Chandigarh(Mohali)Python Training Course in Chandigarh(Mohali)
Python Training Course in Chandigarh(Mohali)
ExcellenceAcadmy
 
12-Lec - Repetition For Loop.pptx
12-Lec - Repetition For Loop.pptx12-Lec - Repetition For Loop.pptx
12-Lec - Repetition For Loop.pptx
AqeelAbbas94
 
Chap 4 c++
Chap 4 c++Chap 4 c++
Bikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa_Thapa_Python_Programming_(Basics).pptxBikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa Thapa
 
4th_Ed_Ch03.pdf
4th_Ed_Ch03.pdf4th_Ed_Ch03.pdf
4th_Ed_Ch03.pdf
ShifatiRabbi
 
Lecture 3
Lecture 3Lecture 3
Lecture 3
Mohammed Khan
 
C programming Control Structure.pptx
C programming Control Structure.pptxC programming Control Structure.pptx
C programming Control Structure.pptx
DEEPAK948083
 

Similar to C code This program will calculate the sum of 10 positive .docx (20)

C++ loop
C++ loop C++ loop
C++ loop
 
Programming egs
Programming egs Programming egs
Programming egs
 
C++ TUTORIAL 2
C++ TUTORIAL 2C++ TUTORIAL 2
C++ TUTORIAL 2
 
Java căn bản - Chapter6
Java căn bản - Chapter6Java căn bản - Chapter6
Java căn bản - Chapter6
 
Advanced Computer Programming..pptx
Advanced Computer Programming..pptxAdvanced Computer Programming..pptx
Advanced Computer Programming..pptx
 
Loop and while Loop
Loop and while LoopLoop and while Loop
Loop and while Loop
 
Chap 4 c++
Chap 4 c++Chap 4 c++
Chap 4 c++
 
3.2 looping statement
3.2 looping statement3.2 looping statement
3.2 looping statement
 
Python programing
Python programingPython programing
Python programing
 
Chapter 5 exercises Balagurusamy Programming ANSI in c
Chapter 5 exercises Balagurusamy Programming ANSI  in cChapter 5 exercises Balagurusamy Programming ANSI  in c
Chapter 5 exercises Balagurusamy Programming ANSI in c
 
Control structure of c
Control structure of cControl structure of c
Control structure of c
 
Lec7 - Loops updated.pptx
Lec7 - Loops updated.pptxLec7 - Loops updated.pptx
Lec7 - Loops updated.pptx
 
Python Training in Chandigarh(Mohali)
Python Training in Chandigarh(Mohali)Python Training in Chandigarh(Mohali)
Python Training in Chandigarh(Mohali)
 
Python Training Course in Chandigarh(Mohali)
Python Training Course in Chandigarh(Mohali)Python Training Course in Chandigarh(Mohali)
Python Training Course in Chandigarh(Mohali)
 
12-Lec - Repetition For Loop.pptx
12-Lec - Repetition For Loop.pptx12-Lec - Repetition For Loop.pptx
12-Lec - Repetition For Loop.pptx
 
Chap 4 c++
Chap 4 c++Chap 4 c++
Chap 4 c++
 
Bikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa_Thapa_Python_Programming_(Basics).pptxBikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa_Thapa_Python_Programming_(Basics).pptx
 
4th_Ed_Ch03.pdf
4th_Ed_Ch03.pdf4th_Ed_Ch03.pdf
4th_Ed_Ch03.pdf
 
Lecture 3
Lecture 3Lecture 3
Lecture 3
 
C programming Control Structure.pptx
C programming Control Structure.pptxC programming Control Structure.pptx
C programming Control Structure.pptx
 

More from aryan532920

According to the NASW Code of Ethics section 6.04 (NASW, 2008), .docx
According to the NASW Code of Ethics section 6.04 (NASW, 2008), .docxAccording to the NASW Code of Ethics section 6.04 (NASW, 2008), .docx
According to the NASW Code of Ethics section 6.04 (NASW, 2008), .docx
aryan532920
 
According to the text, crime has been part of the human condition si.docx
According to the text, crime has been part of the human condition si.docxAccording to the text, crime has been part of the human condition si.docx
According to the text, crime has been part of the human condition si.docx
aryan532920
 
According to Ronald Story and Bruce Laurie, The dozen years between.docx
According to Ronald Story and Bruce Laurie, The dozen years between.docxAccording to Ronald Story and Bruce Laurie, The dozen years between.docx
According to Ronald Story and Bruce Laurie, The dozen years between.docx
aryan532920
 
According to Kirk (2016), most of your time will be spent work with .docx
According to Kirk (2016), most of your time will be spent work with .docxAccording to Kirk (2016), most of your time will be spent work with .docx
According to Kirk (2016), most of your time will be spent work with .docx
aryan532920
 
According to the Council on Social Work Education, Competency 5 Eng.docx
According to the Council on Social Work Education, Competency 5 Eng.docxAccording to the Council on Social Work Education, Competency 5 Eng.docx
According to the Council on Social Work Education, Competency 5 Eng.docx
aryan532920
 
According to Kirk (2016), most of our time will be spent working.docx
According to Kirk (2016), most of our time will be spent working.docxAccording to Kirk (2016), most of our time will be spent working.docx
According to Kirk (2016), most of our time will be spent working.docx
aryan532920
 
According to Kirk (2016), most of your time will be spent working wi.docx
According to Kirk (2016), most of your time will be spent working wi.docxAccording to Kirk (2016), most of your time will be spent working wi.docx
According to Kirk (2016), most of your time will be spent working wi.docx
aryan532920
 
According to Davenport (2014) the organizational value of healthcare.docx
According to Davenport (2014) the organizational value of healthcare.docxAccording to Davenport (2014) the organizational value of healthcare.docx
According to Davenport (2014) the organizational value of healthcare.docx
aryan532920
 
According to the authors, privacy and security go hand in hand; .docx
According to the authors, privacy and security go hand in hand; .docxAccording to the authors, privacy and security go hand in hand; .docx
According to the authors, privacy and security go hand in hand; .docx
aryan532920
 
According to Gilbert and Troitzsch (2005), Foundations of Simula.docx
According to Gilbert and Troitzsch (2005), Foundations of Simula.docxAccording to Gilbert and Troitzsch (2005), Foundations of Simula.docx
According to Gilbert and Troitzsch (2005), Foundations of Simula.docx
aryan532920
 
According to Klein (2016), using ethical absolutism and ethical .docx
According to Klein (2016), using ethical absolutism and ethical .docxAccording to Klein (2016), using ethical absolutism and ethical .docx
According to Klein (2016), using ethical absolutism and ethical .docx
aryan532920
 
According to Franks and Smallwood (2013), information has become.docx
According to Franks and Smallwood (2013), information has become.docxAccording to Franks and Smallwood (2013), information has become.docx
According to Franks and Smallwood (2013), information has become.docx
aryan532920
 
According to the Council on Social Work Education, Competency 5.docx
According to the Council on Social Work Education, Competency 5.docxAccording to the Council on Social Work Education, Competency 5.docx
According to the Council on Social Work Education, Competency 5.docx
aryan532920
 
According to the authors, privacy and security go hand in hand; and .docx
According to the authors, privacy and security go hand in hand; and .docxAccording to the authors, privacy and security go hand in hand; and .docx
According to the authors, privacy and security go hand in hand; and .docx
aryan532920
 
According to recent surveys, China, India, and the Philippines are t.docx
According to recent surveys, China, India, and the Philippines are t.docxAccording to recent surveys, China, India, and the Philippines are t.docx
According to recent surveys, China, India, and the Philippines are t.docx
aryan532920
 
According to the authors, countries that lag behind the rest of the .docx
According to the authors, countries that lag behind the rest of the .docxAccording to the authors, countries that lag behind the rest of the .docx
According to the authors, countries that lag behind the rest of the .docx
aryan532920
 
According to Peskin et al. (2013) in our course reader, Studies on .docx
According to Peskin et al. (2013) in our course reader, Studies on .docxAccording to Peskin et al. (2013) in our course reader, Studies on .docx
According to Peskin et al. (2013) in our course reader, Studies on .docx
aryan532920
 
According to Franks and Smallwood (2013), information has become the.docx
According to Franks and Smallwood (2013), information has become the.docxAccording to Franks and Smallwood (2013), information has become the.docx
According to Franks and Smallwood (2013), information has become the.docx
aryan532920
 
According to Ang (2011), how is Social Media management differen.docx
According to Ang (2011), how is Social Media management differen.docxAccording to Ang (2011), how is Social Media management differen.docx
According to Ang (2011), how is Social Media management differen.docx
aryan532920
 
According to (Alsaidi & Kausar (2018), It is expected that by 2020,.docx
According to (Alsaidi & Kausar (2018), It is expected that by 2020,.docxAccording to (Alsaidi & Kausar (2018), It is expected that by 2020,.docx
According to (Alsaidi & Kausar (2018), It is expected that by 2020,.docx
aryan532920
 

More from aryan532920 (20)

According to the NASW Code of Ethics section 6.04 (NASW, 2008), .docx
According to the NASW Code of Ethics section 6.04 (NASW, 2008), .docxAccording to the NASW Code of Ethics section 6.04 (NASW, 2008), .docx
According to the NASW Code of Ethics section 6.04 (NASW, 2008), .docx
 
According to the text, crime has been part of the human condition si.docx
According to the text, crime has been part of the human condition si.docxAccording to the text, crime has been part of the human condition si.docx
According to the text, crime has been part of the human condition si.docx
 
According to Ronald Story and Bruce Laurie, The dozen years between.docx
According to Ronald Story and Bruce Laurie, The dozen years between.docxAccording to Ronald Story and Bruce Laurie, The dozen years between.docx
According to Ronald Story and Bruce Laurie, The dozen years between.docx
 
According to Kirk (2016), most of your time will be spent work with .docx
According to Kirk (2016), most of your time will be spent work with .docxAccording to Kirk (2016), most of your time will be spent work with .docx
According to Kirk (2016), most of your time will be spent work with .docx
 
According to the Council on Social Work Education, Competency 5 Eng.docx
According to the Council on Social Work Education, Competency 5 Eng.docxAccording to the Council on Social Work Education, Competency 5 Eng.docx
According to the Council on Social Work Education, Competency 5 Eng.docx
 
According to Kirk (2016), most of our time will be spent working.docx
According to Kirk (2016), most of our time will be spent working.docxAccording to Kirk (2016), most of our time will be spent working.docx
According to Kirk (2016), most of our time will be spent working.docx
 
According to Kirk (2016), most of your time will be spent working wi.docx
According to Kirk (2016), most of your time will be spent working wi.docxAccording to Kirk (2016), most of your time will be spent working wi.docx
According to Kirk (2016), most of your time will be spent working wi.docx
 
According to Davenport (2014) the organizational value of healthcare.docx
According to Davenport (2014) the organizational value of healthcare.docxAccording to Davenport (2014) the organizational value of healthcare.docx
According to Davenport (2014) the organizational value of healthcare.docx
 
According to the authors, privacy and security go hand in hand; .docx
According to the authors, privacy and security go hand in hand; .docxAccording to the authors, privacy and security go hand in hand; .docx
According to the authors, privacy and security go hand in hand; .docx
 
According to Gilbert and Troitzsch (2005), Foundations of Simula.docx
According to Gilbert and Troitzsch (2005), Foundations of Simula.docxAccording to Gilbert and Troitzsch (2005), Foundations of Simula.docx
According to Gilbert and Troitzsch (2005), Foundations of Simula.docx
 
According to Klein (2016), using ethical absolutism and ethical .docx
According to Klein (2016), using ethical absolutism and ethical .docxAccording to Klein (2016), using ethical absolutism and ethical .docx
According to Klein (2016), using ethical absolutism and ethical .docx
 
According to Franks and Smallwood (2013), information has become.docx
According to Franks and Smallwood (2013), information has become.docxAccording to Franks and Smallwood (2013), information has become.docx
According to Franks and Smallwood (2013), information has become.docx
 
According to the Council on Social Work Education, Competency 5.docx
According to the Council on Social Work Education, Competency 5.docxAccording to the Council on Social Work Education, Competency 5.docx
According to the Council on Social Work Education, Competency 5.docx
 
According to the authors, privacy and security go hand in hand; and .docx
According to the authors, privacy and security go hand in hand; and .docxAccording to the authors, privacy and security go hand in hand; and .docx
According to the authors, privacy and security go hand in hand; and .docx
 
According to recent surveys, China, India, and the Philippines are t.docx
According to recent surveys, China, India, and the Philippines are t.docxAccording to recent surveys, China, India, and the Philippines are t.docx
According to recent surveys, China, India, and the Philippines are t.docx
 
According to the authors, countries that lag behind the rest of the .docx
According to the authors, countries that lag behind the rest of the .docxAccording to the authors, countries that lag behind the rest of the .docx
According to the authors, countries that lag behind the rest of the .docx
 
According to Peskin et al. (2013) in our course reader, Studies on .docx
According to Peskin et al. (2013) in our course reader, Studies on .docxAccording to Peskin et al. (2013) in our course reader, Studies on .docx
According to Peskin et al. (2013) in our course reader, Studies on .docx
 
According to Franks and Smallwood (2013), information has become the.docx
According to Franks and Smallwood (2013), information has become the.docxAccording to Franks and Smallwood (2013), information has become the.docx
According to Franks and Smallwood (2013), information has become the.docx
 
According to Ang (2011), how is Social Media management differen.docx
According to Ang (2011), how is Social Media management differen.docxAccording to Ang (2011), how is Social Media management differen.docx
According to Ang (2011), how is Social Media management differen.docx
 
According to (Alsaidi & Kausar (2018), It is expected that by 2020,.docx
According to (Alsaidi & Kausar (2018), It is expected that by 2020,.docxAccording to (Alsaidi & Kausar (2018), It is expected that by 2020,.docx
According to (Alsaidi & Kausar (2018), It is expected that by 2020,.docx
 

Recently uploaded

Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
Mohammed Sikander
 
Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
gb193092
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
goswamiyash170123
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 

Recently uploaded (20)

Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
 
Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 

C code This program will calculate the sum of 10 positive .docx

  • 1. // C code // This program will calculate the sum of 10 positive integers. // Developer: Faculty CMIS102 // Date: Jan 31, XXXX #include <stdio.h> #include <stdbool.h> // needed for the Boolean variable debug. int main () { /* variable definition: */ int count, value, sum; int err; float avg; bool debug; /* Initialize */
  • 2. count = 0; sum = 0; avg = 0.0; debug = false; // Loop through to input values while (count < 10) { printf("Enter a positive Integern"); err = scanf("%d", &value); if (debug) printf(" err = %dn",err); if (debug) printf(" value is %dn " , value ); //note the value of debug if (value >= 0) { sum = sum + value; count = count + 1; }
  • 3. else { printf("Value must be positiven"); } } // Calculate avg. // Since sum and count are both integers, this will give you an integer division // Hence, we need to either // Declare sum as a float or... // type cast sum as float (as shown below) avg = (float) sum/count; printf("sum is %dn", sum); printf("average is %fn " , avg ); return 0; }
  • 4. Week 4 Classroom Lecture This week, the new pseudo commands are the Loops (or Repetitive) statements: A Repetitive (or Loop) statement is how you would execute the same block of code multiple times until some exit condition is met. There three types of Loops statements that we will learn. A Loop may be one of two types – pre test or post test. In a pre-test loop, the conditional test must be True before the code enters the loop. In a post-test loop, the code enters the loop first and then the conditional test is performed at the end of the loop to determine whether to exit or not. The three Loop statements are: at least once
  • 5. Until (condition is true) - post test – if condition is True, the code exits the loop - pre test – if the condition is True, the code enters the loop est is an enter conditional End While -pre test – if the condition is True, the code enters the loop – you can use constant, a variable, or an expression – the increment is done at the end of the loop End For NOTE: The module readings has the pseudo-code for a For loop as For i = 1 step 1 to n We will NOT use this nomenclature. NOTE: The module readings also has Input statement without a
  • 6. prompt (Write) to the user as to what to enter. This bad practice as the user will be sitting there and not know that he is supposed to enter something. Your Input statements should always be preceded by a prompt (i.e. Write statement) to the user. -controlled loop o a special value is used to exit the loop o this value is typically an invalid or illogical value such as -1 for a value that is typically positive like age or cost and is typically entered by the user to exit a loop – occurs when your test conditional is never met. Always, check your test condition carefully. -controlled loops o the counter is usually an Integer
  • 7. o Initialize the counter o Increment/Decrement the counter Example for each of the types of loops: Sum of integers from 1 to 10 Set J, sumJ = 0 //Always initialize your counter and variables Repeat Set J = J + 1 //Increment the counter Set sumJ = sumJ + J // Add the current value of J to the sumJ variable Until (J == 10) //When J equals 10, the loop exits Write (“sumJ is: “ + sumJ) //sumJ is: 55 Set J, sumJ = 0 //Always initialize your counter and variables While (J < 10) //Enters the loop if J is less than 10 Set J = J + 1 //Increment the counter Set sumJ = sumJ + J // Add the current value of J to the sumJ variable End While
  • 8. Write (“sumJ is: “ + sumJ) //sumJ is: 55 // OR if you start with 1 … Notice the logic is slightly different…. Set J = 1 Set sumJ = 0 //Always initialize your counter and variables While (J <= 10) //Enters the loop if J is less than or equal to 10 Set sumJ = sumJ + J // Add the current value of J to the sumJ variable Set J = J + 1 //Increment the counter End While Write (“sumJ is: “ + sumJ) //sumJ is: 55 Set sumJ = 0 //Always initialize your counter and variables For (J=1; J <= 10; J++) //J is initialized to 1, Enters the loop if J is less than or equal to 10 Set sumJ = sumJ + J // Add the current value of J to the sumJ variable End While // J is incremented by 1 (i.e. J++) Write (“sumJ is: “ + sumJ) //sumJ is: 55
  • 9. Example: Sentinel-controlled loop Set count, ageSum, avgAge = 0 // Initialize to 0 Set age = 1 //Always initialize your variables- need to set age to 1, so that it enters the loop While (age > 0) //Enters the loop if age is greater than 0 Write (“Please enter your age, enter -1 to exit”) //Prompt the user to enter age or -1 to exit Input age //get the user input If (age > 0) then //test the value of age, if greater than 0, then process your code Set count = count + 1 // increment loop counter, only if valid age Set ageSum = ageSum + age //accumulate the sum of the ages Endif End While //Calculate the average age Set avgAge = ageSum / count //Calculate the average age
  • 10. Example: Sentinel-controlled loop using a Boolean Declare continueEntry AS Boolean Declare count, age AS Integer Declare ageSum, avgAge AS Float //Declare ageSum as Float to avoid Integer division Set continueEntry = True // need to set to True, so that it enters the loop Set count, ageSum, avgAge = 0 // Initialize to 0 Set age = 0 //Always initialize your variables While (continueEntry) //Enters the loop if age is greater than 0 Write (“Please enter your age, enter -1 to exit”) //Prompt the user to enter age or -1 to exit Input age //get the user input If (age > 0) then //test the value of age, if greater than 0, then process your code Set count = count + 1 // increment loop counter, only if valid age Set ageSum = ageSum + age //accumulate the sum of the ages Set continueEntry = True Else Set continueEntry = False //set Boolean to False to exit the loop
  • 11. Endif End While //Calculate the average age If (count > 0) //Test count so that we don’t have division by 0 Set avgAge = ageSum / count //Calculate the average age Endif 1 CMIS 102 Hands-On Lab // Week 4 Overview: This hands-on lab allows you to follow and experiment with the critical steps of developing a program including the program description, Analysis, , Design(program design, pseudocode), Test Plan, and implementation with C code. The example provided uses sequential, repetition statements and nested repetition statements. Program Description: This program will calculate the average of 10 positive integers. The program will ask the user to 10 integers. If any of the
  • 12. values entered is negative, a message will be displayed asking the user to enter a value greater than 0. The program will use a loop to input the data. Analysis: I will use sequential, selection and repetition programming statements. The program will loop for 10 positive numbers, prompting the user to enter a number. I will define three integer variables: count, value and sum. count will store how many times values greater than 0 are entered. value will store the input. Sum will store the sum of all 10 integers. I will define one double number: avg. avg will store the average of the ten positive integers input. The sum will be calculated by this formula: sum = sum + value For example, if the first value entered was 4 and second was 10: sum = sum + value = 0 + 4 sum = 4 + 10 = 14 Values and sum can be input and calculated within a repetition loop: while count <10 Input value sum = sum + value End while Avg can be calculated by: avg = value/count A selection statement can be used inside the loop to make sure the input value is positive. If value >= 0 then
  • 13. count = count + 1 sum = sum + value Else input value End If 2 Program Design: Main // This program will calculate the average of 10 integer numbers // Declare variables // Initialize variables // Loop through 10 numbers // Prompt for positive integer // Get input // test input value for gt 0 if (value > 0)
  • 14. //Increment counter //Accumulate sum Else // display msg to enter a positive integer // Prompt for positive integer // Get input Endif // End loop //Calculate average //Print the results (average) End Test Plan: To verify this program is working properly the input values could be used for testing: Test Case Input Expected Output 1 1 1 1 0 1 2 0 1 3 2 Average = 1.2 2 100 100 100 100 -100 100 200 -200 200 200 200 200 Input a positive value Input a positive value average is 120.0
  • 15. NOTE: test #2 has 12 input numbers because there are two negative numbers. 3 Pseudocode: Main // This program will calculate the average of 10 positive integers. // Declare variables Declare count, value, sum as Integer Declare avg as double //Initialize values Set count=0
  • 16. Set sum = 0 Set avg = 0.0; // Loop through 10 integers While count < 10 Print “Enter a Positive Integer” Input value If (value >=0) sum = sum + value count=count+1 Else Print (“*** Value must be positive ***”) Print “Enter a Positive Integer” Input value End if End While // Calculate average
  • 17. avg = sum/count // Print results Print “Average is “ + avg End //End of Main 4 C Code The following is the C Code that will compile in execute in the online compilers. #include <stdio.h> #include <stdbool.h> // needed for the Boolean variable debug. int main ()
  • 18. { /* variable definition: */ int count, value, sum; int err; float avg; bool debug; /* Initialize */ count = 0; sum = 0; avg = 0.0; debug = false; // Loop through to input values while (count < 10) { printf("Enter a positive Integern"); err = scanf("%d", &value); //note: err is the error code returned by scanf. if (debug) printf(" value is %dn " , value ); //note the value of debug if (debug) printf(" err = %dn",err); // note: err is the error code returned by scanf. if (value >= 0) { sum = sum + value; count = count + 1; } else { printf("Value must be positiven"); } } // Calculate avg. // Since sum and count are both integers, this will give you an integer division // Hence, we need to either // Declare sum as a float or...
  • 19. // type cast sum as float (as shown below) avg = (float) sum/count; printf("sum is %dn", sum); printf("average is %fn " , avg ); return 0; 5 } Setting up the code and the input parameters in ideone.com: Note the input integer values are 1, 1, 1, 0, 1, 2, 0, 1, 3, 2 for this test case. You can change these values to any valid integer values to match your test cases. You should also test with a negative number to make sure the positive integer logic works properly. Note: the input data needs to be entered into the stdin window separated by a space of new line. 6
  • 20. Results from running the programming at ideone.com: 7 Learning Exercises for you to try: 8 1. Change the code to average 20 integers as opposed to 10. Support your experimentation with screen captures of executing the new code. What happens if you change the formatter to %.2f printf("average is %.2fn " , avg ); 2. 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. To help in your analysis try as input 1 2 3 a 4 5 Hint: activate this line if(debug) printf(" value is %dn " , value ); after the scanf statement that reads in the value. Activate by changing the value of debug.
  • 21. Next try as input 1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9 10.5 What happens? 3. Modify the code to allow the user to enter an unspecified 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). You may need to conduct some research on your own to solve this problem. 4. 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. Submission Submit a neatly organized word (or PDF) document that demonstrates you successfully executed this lab on your machine using an online compiler. You should provide a screen capture of the resulting output. Also, provide the answers, associated screen captures, C Code and descriptions of your successful completion of learning exercises 1, 2, 3 and 4. The answers to the learning exercises, screen captures, C code and descriptions can be included in the same
  • 22. neatly organized document you prepared as you ran this lab. Note the code can be embedded in the word document. However; be sure all code compiles and runs perfectly before submitting the document. Submit the C-code for no. 3 as a separate .txt (or .c ) file. Submit your document no later than the due date listed in the syllabus or calendar. Grading guidelines Submission points No. 1 Successfully demonstrates execution of this lab with online compiler for exercise no. 1. Includes a screen capture of executing the new code. 2 No. 2 Describes what happens if you entered a value other than an integer? Support your experimentation with screen captures of executing the code. 2 No. 3 Modifies the C code to allow the user to enter an unspecified number of
  • 23. positive integers and calculate the average. Submit C code (as .c or .txt) file screen captures of executing the code. 3 No. 4 Provides a new test table with at least 3 distinct test cases listing input and expected output your program. Should include at least one negative value. 2 Document is well-organized, and contains minimal spelling and grammatical errors. 1 Total 10 9