Semester : S1 and S2
Subject : Computer Programming
Year : 2018
Term : MARCH
Branch : BIOTECHNOLOGY
Scheme : 2015 Full Time
Course Code : CS 100
Page:21
#include
multiplyNumbers(int n);
int main()
{
int n; _ printf("Enter a positive integer: ");
scanf("%d", &n); = printf("Factorial of %d =
%ld", n, multiplyNumbers(n)); — return 0;
}
long int multiplyNumbers(int n)
{
if (n >= 1) return
n*multiplyNumbers(n-1); 656 return
1;
}
Output
Enter a positive integer: 6
Factorial of 6 = 720
19.a)
Let us see the correct ways for swapping strings:
Method 1(Swap Pointers)
If you are using character pointer for strings (not arrays) then change str1 and str2 to point each other’s
data. 1.6., swap pointers. Ina function, if we want to change a pointer (and obviously we want changes to
be reflected outside the function) then we need to pass a pointer to the pointer.
#include
/* Swaps strings by swapping pointers */ void
swap1(char **str1_ptr, char **str2_ptr)
{
char *temp = *str1_ptr;
*str1_ptr = *str2_ptr;
*str2_ptr = temp;
} int main()
{