Question

Write a C function named  f such that … the prototype of function  f is … unsigned long...

  • Write a C function named  f such that …
    • the prototype of function  f is …
      •   unsigned long int f ( unsigned long int X, unsigned long int Y ) 
    • function  f returns …
      • the nonnegative integer  Z  such that   X 2  +   Y 2  =   Z 2  if such a nonnegative integer  Z  exists
      • zero if there is no nonnegative integer  Z  such that   X 2  +   Y 2  =   Z 2
  • Example 1
    • If   X = 3  and   Y = 4 , then function  f returns   5    because   5  is the nonnegative integer such that   32 + 42  = 52  .
  • Example 2
    • If   X = 2  and   Y = 5 , then function  f returns   0    because there is no nonnegative integer  Z  such that   22 + 52  = Z2  .
0 0
Add a comment Improve this question Transcribed image text
Answer #1
unsigned long int f ( unsigned long int X, unsigned long int Y ){
   unsigned long int result = X*X + Y*Y;
   unsigned long int Z = 0;
   while(result > (Z*Z)){
       Z = Z + 1;
   }
   if(result == (Z*Z)){
      return Z;
   }
   else{
      return 0;
   }
}
Add a comment
Know the answer?
Add Answer to:
Write a C function named  f such that … the prototype of function  f is … unsigned long...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Question 14; Write a C function named isSymmetric, the prototype of which is given below, that...

    Question 14; Write a C function named isSymmetric, the prototype of which is given below, that returns 1 if the elements of an array of integers named myArray of size n are symmetric around the middle. If the array elements are not symmetric, the function should return 0. Both the array and its size are specified as parameters. (10 marks) Clue: Array myArray of size n is symmetric if myArray[0] is equal to myArray[n-1], myArray[1] is equal to myArray[n-2], and...

  • 3. (12) Write a function named getSumSquares. You can skip writing the function prototype. This function...

    3. (12) Write a function named getSumSquares. You can skip writing the function prototype. This function has two int arguments called first and last. The function is to add up the tube of each number from first to last and return the total. (Note: the easy way to get the square of a number a is with: a * a). Square To see how the function works, here is an example. After the statement int c = getSumSquares (2, 4);...

  • Write a C function named date() that receives an integer number of the long date, date...

    Write a C function named date() that receives an integer number of the long date, date form is yyyymmdd, such as 20070412; and the addresses of three variables named month, day, and year. determines the corresponding month, day, and year; and returns these three values to the calling function. For example, if date() is called using the statement     longdate=20200411; date(longdate, &month, &day, &year); the number 4 should be returned in month, the number 11 in day, and the number...

  • 11 Write a function with the following prototype: /* Determine whether arguments can be added without overflow */ int u...

    11 Write a function with the following prototype: /* Determine whether arguments can be added without overflow */ int uadd_ok (unsigned x, unsigned y); This function should return 1 if arguments x and y can be added without causing overflow 11 Write a function with the following prototype: /* Determine whether arguments can be added without overflow */ int uadd_ok (unsigned x, unsigned y); This function should return 1 if arguments x and y can be added without causing overflow

  • Write a C function named isSymmetric, the prototype of which is given below, that returns 1...

    Write a C function named isSymmetric, the prototype of which is given below, that returns 1 if the elements of an array of integers named myArray of size n are symmetric around the middle. If the array elements are not symmetric, the function should return 0. Both the array and its size are specified as parameters.

  • write C code that uses pointers, arrays, and C strings. 3. Write a function called pow_xy....

    write C code that uses pointers, arrays, and C strings. 3. Write a function called pow_xy. The function should be passed 2 parameters, as illustrated in the prototype below. int pow_xy(int *xptr, int y); Assuming that xptr contains the address of variable x, pow_xy should compute x to the y power, and store the result as the new value of x. The function should also return the result. Do not use the built-in C function pow. For the remaining problems,...

  • C programming KAM5 Write a function unsigned long long int factorial(int num) to compute the factorial...

    C programming KAM5 Write a function unsigned long long int factorial(int num) to compute the factorial of a number. The factorial of a number is given by n! = 1*2* ... *n So 1! = 1, 2! = 1*2, 3! = 1*2*3 ... For example: Test Result printf("%llu\n", factorial(5)); 120 printf("%lu\n", factorial(20)); 2432902008176640000

  • C++ Write a recursive function named sumSquares that returns the sum of the squares of the...

    C++ Write a recursive function named sumSquares that returns the sum of the squares of the numbers from  to num, in which num is a nonnegative int variable. Do not use global variables; use the appropriate parameters. Also write a program to test your function.

  • Create a function, void allocate_mem(unsigned int** input_one, unsigned int** input_two, unsigned long int** output, int num_ints)...

    Create a function, void allocate_mem(unsigned int** input_one, unsigned int** input_two, unsigned long int** output, int num_ints) in C. This function allocates enough memory to the three arrays to store num_ints elements each. This function should exit with EXIT_FAILURE if the program fails to allocate the memory. input parameters: unsigned int* input_one unsigned int* input_two unsigned long int* output int num_ints return parameters: none Do NOT hard code the size of the unsigned (long) integer arrays

  • you need to write a C function named rem. The prototype is: int rem(char*, char*); The...

    you need to write a C function named rem. The prototype is: int rem(char*, char*); The function accepts 2 strings: the first is a string of text to process; the second is where the output will be placed. rem() should remove all occurrences of a lowercase 'x' from the first string, and save the resulting string in the second arg. You may use the strlen() function; no other built-in fuctions should be used. Test your program thoroughly. Then, once you...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT