All Questions

Chemistry - Class 12

Follow
Showing 41 - 41 out of 41 Questions
1486 Views

W.a.p. in c language to calculate power of any number without using string library function.

Debosmitha Bhattacharyya Student Expert 29th Nov, 2018

Hello,

Since you've mentioned "without using recursion" I've written the following code using recursion.

#include <stdio.h>

long power (int num, int pow)

{

    if (pow)

    {

        return (num * power(num, pow - 1));

    }

    return 1;

int main()

{

    int pow, num;

    long result;

    printf("Enter a number: ");

    scanf("%d", &num);

    printf("Enter it's power: ");

    scanf("%d", &pow);

    result = power(num, pow);

    printf("%d^%d is %ld", num, pow, result);

    return 0;

}

The question have been saved in answer later, you can access it from your profile anytime. Access now