Monday, July 2, 2018

C to find power of a number using recurrsion

#include <stdio.h>

int power(int n1, int n2);

int main()
{
    int base, powerRaised, result;

    printf("Enter base number: ");
    scanf("%d",&base);

    printf("Enter power number(positive integer): ");
    scanf("%d",&powerRaised);

    result = power(base, powerRaised);

    printf("%d^%d = %d", base, powerRaised, result);
    return 0;
}

int power(int base, int powerRaised)
{
    if (powerRaised != 0)
        return (base*power(base, powerRaised-1));
    else
        return 1;
}

No comments:

Post a Comment

How to integrate standard LLMs with custom data to create RAG applications

 Integrating standard Large Language Models (LLMs) with custom data to build Retrieval-Augmented Generation (RAG) applications involves a mu...