C Program Functions using Pointers Create a function modify that accepts an integer and divides the integer by 2 if it is even. If the integer is odd, add one and divide it by 2. The function does not return anything. In the main function, write a program that asks for an integer input and call the modify function by passing in the reference of that variable as a parameter. An initial code is provided for you. Just fill in the blanks. Input 1. One line containing an integer input Output Enter a number: 5 Before: 5 After: 3

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter10: Pointers
Section: Chapter Questions
Problem 3PP
icon
Related questions
Question

C Program Functions using Pointers

Create a function modify that accepts an integer and divides the integer by 2 if it is even. If the integer is odd, add one and divide it by 2. The function does not return anything. 

In the main function, write a program that asks for an integer input and call the modify function by passing in the reference of that variable as a parameter.

 

An initial code is provided for you. Just fill in the blanks.

Input

1. One line containing an integer input

Output

Enter a number: 5
Before: 5
After: 3
1. Pass-by-reference in Functions
Using Pointers Practice I
by CodeChum Admin
Create a function modify that accepts an integer and divides
the integer by 2 if it is even. If the integer is odd, add one and
divide it by 2. The function does not return anything.
In the main function, write a program that asks for an integer
input and call the modify function by passing in the reference
of that variable as a parameter.
An initial code is provided for you. Just fill in the blanks.
Input
1. One line containing an integer input
Output
Enter a number: 5
Before: 5
After: 3
main.c
1
2
3
4
5
6
7
8
2
9
10
11
12
13
#include <stdio.h>
int main(void) {
int x;
}
printf("Enter a number: ");
scanf("%d", &x);
printf("Before: %d\n", x);
printf("After: %d", x);
return 0;
Test Cases
Constraints
O Constraint 1
This code must call the function inside the main
O Constraint 2
Must call use pass-by-reference method
Test Cases
○ Test Case 1
Your Output
No Output
Expected Output
Enter a number: 100
Before: 100
After: 50
Transcribed Image Text:1. Pass-by-reference in Functions Using Pointers Practice I by CodeChum Admin Create a function modify that accepts an integer and divides the integer by 2 if it is even. If the integer is odd, add one and divide it by 2. The function does not return anything. In the main function, write a program that asks for an integer input and call the modify function by passing in the reference of that variable as a parameter. An initial code is provided for you. Just fill in the blanks. Input 1. One line containing an integer input Output Enter a number: 5 Before: 5 After: 3 main.c 1 2 3 4 5 6 7 8 2 9 10 11 12 13 #include <stdio.h> int main(void) { int x; } printf("Enter a number: "); scanf("%d", &x); printf("Before: %d\n", x); printf("After: %d", x); return 0; Test Cases Constraints O Constraint 1 This code must call the function inside the main O Constraint 2 Must call use pass-by-reference method Test Cases ○ Test Case 1 Your Output No Output Expected Output Enter a number: 100 Before: 100 After: 50
Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Functions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning