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

Amity University-Noida BCA Ad...
Apply
Among top 100 Universities Globally in the Times Higher Education (THE) Interdisciplinary Science Rankings 2026
Victoria University, Delhi NCR
Apply
Apply for UG & PG programmes from Victoria University, Delhi NCR Campus
University of Liverpool, Beng...
Apply
Study at a world-renowned UK university in India | Admissions open for UG & PG programs.
Guru Nanak College - BCA 2026
Apply
3000+ Successful Placements | 100+ Leading Recruiters
University of Bristol, Mumbai...
Apply
Bristol's expertise meets Mumbai's innovation. Admissions open for UG & PG programmes
Amity University-Noida MCA 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