/*Your task is to create the special functions used by this routine, which are shown in blue in the above program. You need to write the functions so that they can be used by the main routine as shown. In other words, do not change the way the functions are used, rather write your functions to accept the parameters and return the values needed to make the program work properly. Be careful to notice where pointers and variable addresses are used - the idea of this Lab is to practice writing code that uses pointers*/
include <stdio.h>
#include <stdlib.h>
void swapArgs(int *parmA,int *parmB)
{
int temp = *parmA;
*parmA = *parmB;
*parmB = temp;
}
/* MAIN */
int main(int argc, char **argv) {
if (argc != 3) {
printf("?Invalid number of arguments\n");
system("pause");
exit(1);
}
int parmA = atoi(argv[1]);
int parmB = atoi(argv[2]);
/* Part A: Swap the values. Value in parmA is moved to parmB and vice versa */
/* Reset the original values after we print the result */
printf("A=%d, B=%d. ",parmA,parmB);
swapArgs(&parmA,&parmB);
printf("Swapped values A=%d, B=%d.\n",parmA,parmB);
parmA = atoi(argv[1]);
parmB = atoi(argv[2]);
/* Part B: Divide parmA by parmB. Put the quotient in parmA, remainder in parmB */
/* Reset the original values after we print the result */
printf("Quotient of %d / %d is ",parmA,parmB);
// divideArgs(&parmA, &parmB);
printf("%d, remainder is %d\n",parmA,parmB);
parmA = atoi(argv[1]);
parmB = atoi(argv[2]);
/* Part C: Raise parmA to the power of parmB. Return pointer to the result */
/* Reset the original values after we print the result */
// printf("%d raised to the %d power is %.0lf\n",parmA,parmB,*powerArgs(&parmA, &parmB));
parmA = atoi(argv[1]);
parmB = atoi(argv[2]);
/* Extra credit: Fibonacci generator function. The first call to fibArgs returns the
first Fibonacci number (0) and each subsequent call to fibArgs returns the
next Fibonacci number. In this case parmA will specify the number of
Fibonacci numbers to display. Fibonacci numbers:
F(0) = 0
F(1) = 1
F(n) = F(n-1)+F(n-2)
The first few numbers are: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55
*/
int idx;
printf("The first %d Fibonacci Numbers are: ",parmA);
for(idx=0; idx < parmA; idx++) {
// printf(" %d",*fibArgs());
}
printf("\n");
system("pause");
exit(0);
}