C code

288 views 3 pages ~ 602 words Print

Modify the C code to add 10 integers instead of 5? (Hint: Avoid using arrays or Loops for this. We’ll be employing those features in a week or so.) Support your experimentation with a screen capture of the new code being executed.

Modify the code you wrote in step 1 to print an additional statement if the sum of the values is negative (Hint: Consider modifying the existing selection statement) Support your experimentation with a screen capture of the new code being executed.

Create a new test table with at least three separate test cases that identify the input and anticipated result for the code you prepared in step 2. // C code

// This program will calculate the sum of 10 integers.

// Date: 26 June 201

#include

int main ()

{

/* variable definition: */

int value1,value2,value3,value4,value5;

float value6,value7,value8,value9,value10,sum;

/* Initialize sum */

sum = 0;

printf(“Enter an Integer or Float for value1\n”);

scanf(“%d”, &value1);

printf(“Enter an Integer or Float for value2\n”);

scanf(“%d”, &value2);

printf(“Enter an Integer or Float for value3\n”);

scanf(“%d”, &value3);

printf(“Enter an Integer or Float for value4\n”);

scanf(“%d”, &value4);

printf(“Enter an Integer or Float for value5\n”);

scanf(“%d”, &value5);

printf(“Enter an Integer or Float for value6\n”);

scanf(“%f”, &value6);

printf(“Enter an Integer or Float for value7\n”);

scanf(“%f”, &value7);

printf(“Enter an Integer or Float for value8\n”);

scanf(“%f”, &value8);

printf(“Enter an Integer or Float for value9\n”);

scanf(“%f”, &value9);

printf(“Enter an Integer or Float for value10\n”);

scanf(“%f”, &value10);

sum = value1 + value2 + value3 + value4 + value5 + value6 + value7 + value8 + value9 + value10;

printf(“Sum is %.1f\n ” , sum );

if (sum >50)

printf(“Sum is over 50\n”);

return 0;

}

Test Case

Input

Expected Output

1

value1=1

value2=2

value3=3

value4=3

Value5=4

Value6=5

Value7=5

Value8=6

Value9=7

Value10=8

Sum=44.0

2

value1=5

value2=10

value3=15

value4=20

Value5=25

Value6=30

Value7=35

Value8=40

Value9=45

Value10=50

Sum=275.0

Sum is over 50.

3

value1=0

value2=-0

value3=0

value4=0

Value5=0

Value6=0

Value7=0

Value8=0

Value9=0

Value10=0

Sum=0

Test 1

Test 2

Test 3

Create your own C code implementation of one of the following mathematical formulas:

a. y = mx + b; (slope of a line) Assume the user will be prompted to input m, x and b and the program will calculate y. If the value of y is greater than 10, inform the user the value is greater than 10.

b. a = PI * r*r; (area of circle). Assume the user will be prompted to input the radius r. You can define PI as 3.1416. . If the value of a is greater than 10, inform the user the value is greater than 10.

c. v = 4/3 PI r*r; (volume of sphere) Assume the user will be prompted to input the radius r. You can define PI at 3.1416. If the value of v is greater than 10, inform the user the value is greater than 10.

Be sure you provide not only the C code but a test table with at least 3 distinct test cases listing input and expected output your mathematical formula.

C Code

// C code

// This program will calculate the slope of a line.

// Date: 22 June 2017

#include

int main ()

{

/* variable definition: */

int m, x, b, y;

/* Initialize calculation */

y = 0;

printf(“Enter an Integer for m\n”);

scanf(“%d”, &m);

printf(“Enter an Integer for x\n”);

scanf(“%d”, &x);

printf(“Enter an Integer for b\n”);

scanf(“%d”, &b);

y = m*x + b;

printf(“Slope of the line is %d\n ” , y );

if ( y > 10)

printf(“the value is greater than 10\n”);

return 0;

}

Test Table

Test Case

Input

Expected Output

1

m = 4

x = 7

b = 3

Y = 20

The value is greater than 10

2

m = -8

x = 4

b = 3

Y = -21

3

m = 0

x = 0

b = 0

Y = 0

Test 1

Test 2

Test 3

May 24, 2023
Category:

Science Health

Number of pages

3

Number of words

602

Downloads:

62

Writer #

Rate:

5

Expertise Experiment
Verified writer

LuckyStrike has helped me with my English and grammar as I asked him for editing and proofreading tasks. When I need professional fixing of my papers, I contact my writer. A great writer who will make your writing perfect.

Hire Writer

Use this essay example as a template for assignments, a source of information, and to borrow arguments and ideas for your paper. Remember, it is publicly available to other students and search engines, so direct copying may result in plagiarism.

Eliminate the stress of research and writing!

Hire one of our experts to create a completely original paper even in 3 hours!

Hire a Pro