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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education