To evaluate a^b using function using C


Levels of difficulty: / perform operation:

C program to evaluate a^b using function.


C Program

#include <stdio.h>
#include <conio.h>
unsigned long power(int,int);
void main()
{
	int num,pow;
	unsigned long res;
	clrscr();
	printf("\nENTER THE NUMBER: ");
	scanf("%d",&num);
	printf("\nENTER THE POWER: ");
	scanf("%d",&pow);
	res=power(num,pow);
	printf("\n%d TO THE POWER %d IS %lu",num,pow,res);
	getch();
}
unsigned long power(int a,int b)
{
	int i;
	unsigned long prod=1;
	for(i=1;i<=b;i++)
		prod=prod*a;
	return(prod);
}


Output







Quantitative Aptitude
Reasoning
Programming
Interview