A simple C program to calculate the power of a number using recursion.
int power(int n1, int n2);
int base, powerRaised, result;
printf("Enter base number: ");
printf("Enter power number(positive integer): ");
result = power(base, powerRaised);
printf("%d^%d = %d", base, powerRaised, result);
int power(int base, int powerRaised)
if (powerRaised != 0)
return (base*power(base, powerRaised-1));
Enter base number: 3
Enter power number(positive integer): 4
3^4 = 81
C Program to Add Two Complex Numbers by Passing Structure to a Function
In the structure complex, we are using float datatype for variables, real and imag since our concern is to add any two complex numbers with a possible fractional value.
In the main() function, the real part and the imaginary part of the complex numbers are taken separtely using scanf().
The structures n1 and n2 are passed as an argument of function add(). The function computes the sum and returns the structure variable temp to the main() function.
The final result is printed using printf() throught the main() function.