Friday, March 7, 2014

WRITE A FUNCTION POWER TO CALCULATE A FLOATING POINT NUMBER TO BE RAISED TO AN INTEGER POWER

#include<conio.h>
#include<stdio.h>
#include<math.h>
void main()
{
void power(float,int);
int p;
float n;
clrscr();
printf("enter the number\n");
scanf("%f",&n);
printf("\nenter the power\n");
scanf("%d",&p);
power(n,p);
getch();
}
void power(float n,int p)
{
float r=1;
int i;
for(i=1;i<=p;i++)
{
r=r*n;
}
printf("%f to the power %d is %f",n,p,r);
}

No comments:

Post a Comment