top of page
Search

# CSCI2122 Assignment 3 System Programming Solution int sub_test(int32_t x, int32_t y)

Updated: Aug 16

CSCI2122 Assignment 3 System Programming Solution in C programming.

Question

 Complete the function prototype:

int sub_test(int32_t x, int32_t y)

to return `1' if either the calculations x - y and y - x does not over

ow.

 See Figure 1 for an example of how such a function is used by main.

 You may assume that the values for a and b are both legal int32 t values.

 Constraints:

{ Your solution may only include the stdint.h library.

{ You cannot employ the division, multiplication or modulo operators.

{ Conditionals (if -- else or ?:) and switch statements cannot be used.

{ No form of loop should be used.

#include <stdio.h>

#include <stdint.h> // do not include further libraries or macros

int sub_test(int32_t x, int32_t y); // prototype declared

int main(void) // do not make any changes to main

{

int32_t a, b;

printf("Enter integer: ");

scanf("%d", &a);

b = -a;

printf("difference of %d and %d ", a, b);

if (sub_test(a, b))

{

printf("CAN be expressed without overflow\n a - b = %d and b - a = %d\n", a - b, b - a);

}

else printf("CANNOT be expressed without overflow\n");

return 0;

}

int sub_test(int32_t x, int32_t y) // this is the function that needs completion

{

// make sure that you conform to the code usage constraints

} // you only need to submit your code for this function

Figure 1: Example of main calling your function int sub test(int32_t x, int32_t y) .

Important { you cannot assume that the value for b will always be the negative of a. You

may assume that the values for a and b are both legal int32_t values

For 100% Accurate solution Please WhatsApp at:

+91 - 995 314 1035 Solution Includes: Plagiarism and AI report with 100% Accuracy. 