Question: C Programming: Explain in words the algorithm below and the process that was used to produce the output. What is the output of the following
C Programming: Explain in words the algorithm below and the process that was used to produce the output. What is the output of the following c program? #include int key(int num1, int num2); int main(void){ int num1, num2, sign; printf(" Enter the numbers: "); scanf(" %d%d", &num1, &num2); sign = 2; if((num1 < 0) && (num2 > 0)){ num1 = -num1; sign = -2; } else if((num1 > 0) && (num2 < 0)) { num2 = -num2; sign = -2; } else if((num1 < 0) && (num2 < 0)) { num1 = -num1; num2 = -num2; } if(num1 > num2) printf(" %d ", sign*key(num1, num2)); else printf(" %d ", sign*key(num2, num1)); return 0; } int key(int n1, int n2) { if(n2 == 1) return n1; else return n1 + key(n1, n2-1); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
