Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Starter Code: #include void swapIncre(int, int, int); int main( ) { int a, b,c; /* Input three integers*/ scanf(%d %d %d, &a, &b,&c); while(a !=

image text in transcribedimage text in transcribed

Starter Code:

#include  void swapIncre(int, int, int); int main( ) { int a, b,c; /* Input three integers*/ scanf("%d %d %d", &a, &b,&c); while(a != -1) { printf("Original inputs: a:%-4d b:%-4d c:%-4d ", a, b,c); swapIncre(a,b,c); printf("Rearranged inputs: a:%-4d b:%-4d c:%-4d ", a, b,c); /* read again */ scanf("%d %d %d", &a, &b,&c); } } void swapIncre(int x, int y, int z){ int temp = x; x = z; z = temp; y *= 2; }

Sample Input:

3 5 6 2 67 -1 -12 45 66 66 55 1404 22 3 412 -2 44 6 -1 55 605
Specification Write an ANSI-C program that reads three integers line by line, and modify the input values. Implementation Download file lab5A.c to start off. .The program reads user inputs from stdin line by line. Each line of input contains 3 integers separated by blanks. A line that has the first number being -1 indicates the end of input. Store the 3 input integers into variable a, b and c; Function swapIncre() is called in main () with an aim to change the values of a, b and c in such a way that, after function swapIncre returns, a stores the third input value and c stores the first input value (i.e., a and c swap values), and b's value is doubled. Compile and run the program and observe unsurprisingly that the values of a, b and c are not changed at all (why?) Modify the program so that it works correctly, as shown in the sample inputs/outputs below. You should only modify function swapIncre and the statement in main that calls this function. No global variables should be used. 12 -3 30 original inputs: a:12 Rearranged inputs: a: 30 C: 30 C:12 1 2 3 red 309 % cat inputA.txt 2 67 -1 12 45 66 66 55 1404 22 3 412 2 44 6 1 55 605 red 310 % a.out inputA.txt Original inputs: a: 3 Rearranged inputs: a:6 c:6 C:3 b:10 Original inputs: a: 2 Rearranged inputs: a:-1 b:67 b:134C:2 C:-1 Original inputs: a:-12 b:45 Rearranged inputs: a:66 C:66 c:-12 b:90 Original inputs: a:6 Rearranged inputs :a:1404 b:55 b:110 C:1404 c:66 Original inputs: Rearranged inputs : a: 2 a:412 C:412 C:22 b:6 Original inputs: a: Rearranged inputs: a:6 b:44 b:88 c:6 C:-2

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions