C Program To Compute A Power N

#include <stdio.h>
int power(int a, int n)
{
    if (n == 0)
    {
        return 1;
    }
    else
    {
        return a * power(a, n - 1);
    }
}
int main()
{
    int a, n, x;
    printf("Enter a non-zero real number: ");
    scanf("%d", &a);
    printf("Enter positive power: ");
    scanf("%d", &n);
    x = power(a, n);
    printf("The value of %d ^ %d = %d ", a, n, x);
}


C Program To Find GCD Using Recursion

#include <stdio.h>
int hcf(int n1, int n2);
int main()
{
    int n1, n2;
    printf("Enter values of a and b : ");
    scanf("%d %d", &n1, &n2);

    printf("G.C.D (%d , %d) = %d.", n1, n2, hcf(n1, n2));
    return 0;
}

int hcf(int n1, int n2)
{
    if (n2 != 0)
        return hcf(n2, n1 % n2);
    else
        return n1;
}
Share To:

Arogya Thapa Magar

Post A Comment:

0 comments so far,add yours