Write a C function to compute the following output (int) based on two input (int) variables:
output = a*a + b*b - 2*a*b
If the value of output is '0', then return -1 instead.
Call the C function 4 times from main() with values of 'a' and 'b' as follows and print output values for each case.
a = 3, b = 4
a = 1, b = 1
a = -2 b = 3
a = -4 b = -5
#include <stdio.h> int getResult(int a, int b){ int result = a*a + b*b - 2*a*b; if(result==0){ return -1; } else{ return result; } } int main() { printf("%d\n",getResult(3,4)); printf("%d\n",getResult(1,1)); printf("%d\n",getResult(-2,3)); printf("%d\n",getResult(-4,-5)); return 0; }
Get Answers For Free
Most questions answered within 1 hours.