Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C Programming Question 1 Given the following code, write a function g() with two int parameters x and y , that computes the sum and

C Programming

Question 1

Given the following code, write a function g() with two int parameters x and y, that computes the sum and product of x and y. The sum is a global variable, and the product is the value returned by g().

#include  int g(int, int); int sum; int main(void) { int product = g(3, 4); printf("Sum=%d ", sum); printf("Product=%d ", product); } int g(int x, int y) { //fill in code here }

-

Question 2

What happens if you call a function with an actual parameter whose type is char, if the formal parameter has type float?

Can an overflow occur?

-

Question 3

Part A

Write the code for a function named cube_volume. The function takes one parameter, the side of a cube, and calculates the volume of a cube. Assume that all values are of type float.

Part B

Provide the code that would be used in main() to use the function (call it or invoke it) and display the result that it returns.

-

Question 4

Given the following code, what is printed?

void f( int a[10] ) { printf(%d , a[3]); a[3] = a[3] + 900; } int main (void) { int a[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; (void) f( a ); (void) f( a ); printf(%d , a[3]); return 0; } 

-

Question 5

Write a recursive function named rev() that reads the characters in a line and outputs them in reverse order.

-

Question 6

Write a function named flip() which 1/3 of the time randomly returns the value -1, 1/3 of the time returns 0, and 1/3 of the time returns +1.

Include code in main() that invokes the flip() function 15 times and displays the value returned each time.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Spatio Temporal Database Management International Workshop Stdbm 99 Edinburgh Scotland September 10 11 1999 Proceedings Lncs 1678

Authors: Michael H. Bohlen ,Christian S. Jensen ,Michel O. Scholl

1999th Edition

3540664017, 978-3540664017

More Books

Students also viewed these Databases questions

Question

Familiarity with transmission substation equipment desirable

Answered: 1 week ago