1486 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

RV University, Bangalore | BC...
Apply
Comprehensive education for the tech-driven era. Cutting-edge labs and facilities. Merit-based scholarships available
ICFAI Mizoram BCA Admissions ...
Apply
Merit Scholarships available
Jaypee University MCA Admissi...
Apply
Highest CTC 94.25 LPA | Average CTC 13,24 LPA Approved by UGC & AICTC | Accredited by NBA & NAAC A Grade | 98% Students Placed | 260+ Recruiters
Amity University-Noida MCA Ad...
Apply
Among top 100 Universities Globally in the Times Higher Education (THE) Interdisciplinary Science Rankings 2026
SRM University, Chennai Scien...
Apply
NAAC A++ Accredited | Ranked #12 by NIRF
SRM University, Chennai Scien...
Apply
NAAC A++ Accredited | Ranked #11 by NIRF
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