1443 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

UEM Jaipur MCA Admissions 2025
Apply
Scholarships to meritorious students | UGC recognized university
Chanakya University MCA Admis...
Apply
Merit Based Scholarships | Pragmatic Exposure Through Collaborations and Live Projects
Amity University | BCA Admiss...
Apply
Ranked amongst top 3% universities globally (QS Rankings)
Chanakya University BCA Admis...
Apply
Scholarships Available | Approved by UGC
UEM Jaipur BCA Admissions 2025
Apply
Scholarships to meritorious students | UGC recognized university
IIM Indore MMS Program
Apply
Apply for IIM Indore Master of Management Studies program
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