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
Amity University-Noida MCA Ad...
Apply
Among top 100 Universities Globally in the Times Higher Education (THE) Interdisciplinary Science Rankings 2026
KIET MCA Admissions 2026
Apply
Affiliated to AKTU | Approved by AICTE | Accredited by NAAC A+ | Rs. 48.89 LPA Highest CTC | Microsoft, Samsung, Infosys, Adobe, Amazon | NIRF-2023...
UPES Dehradun BCA Admissions ...
Apply
Ranked #45 Among Universities in India by NIRF | 1950+ Students Placed, 91% Placement, 800+ Recruiters
Amity University-Noida BCA Ad...
Apply
Among top 100 Universities Globally in the Times Higher Education (THE) Interdisciplinary Science Rankings 2026
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