function to find power of any numbers in C

C, C++, etc Programing examples. Post as many you can. Test the programs and discuss about the output of the programes.
Forum rules
Please Discuss & post only about the programes and its Output

function to find power of any numbers in C

Postby kantisuthar » Sat Apr 16, 2011 2:57 pm

include<stdio.h>
#include<conio.h>
long int power(int,int);
void main()
{
int x,n,ans;
clrscr();
printf("\n\t Enter any number : ");
scanf("%d",&n);
printf("\n\t Enter power : ");
scanf("%d",&x);
ans=power(n,x);
printf("\n\t %d ^ %d = %d",n,x,ans);
getch();
}
long int power(int y,int number)
{
long int result;
int i;
result=1;
for(i=1;i<=number;number--)
{
result=result*y;
}
return(result);
}
kantisuthar
Registered User
 
Posts: 6
Joined: Thu Apr 14, 2011 7:22 pm
membership: Associate Member of The Institution of Engineers (India)- AMIE

ad
 

Return to Computer Notes : Some Sample Programs

Who is online

Users browsing this forum: No registered users and 0 guests