1485 Views

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


Prabal kaushik 29th Nov, 2018
Answer (1)
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;

}

Related Questions

Amity University | MCA Admiss...
Apply
Ranked amongst top 3% universities globally (QS Rankings)
Amity University | BCA Admiss...
Apply
Ranked amongst top 3% universities globally (QS Rankings)
TMV, Pune | M.Sc Computer App...
Apply
2-year postgraduate program focusing on advanced computing and IT applications
JSS University Noida MCA 2025
Apply
170+ Recruiters Including Samsung, Zomato, LG, Adobe and many more | Highest CTC 47 LPA
Graphic Era (Deemed to be Uni...
Apply
NAAC A+ Grade | Among top 100 universities of India (NIRF 2024) | 40 crore+ scholarships distributed
NIELIT University(Govt. of In...
Apply
Campuses in Ropar, Agartala, Aizawl, Ajmer, Aurangabad, Calicut, Imphal, Itanagar, Kohima, Gorakhpur, Patna & Srinagar
View All Application Forms

Download the Careers360 App on your Android phone

Regular exam updates, QnA, Predictors, College Applications & E-books now on your Mobile

150M+ Students
30,000+ Colleges
500+ Exams
1500+ E-books