Radical Developers welcomes all the visitors to be a member of the team. Come join us. Its all about open-source concept. All Programs are written and tested in MacOS X, Unix, Linux and may not match with the outputs of Turbo C++ in Windows

Sunday, January 9, 2011

Write a function power(a,b) to calculate the value of a raised to b.


Source Code :

#include<stdio.h>
int power(int a,int b)
{
      int i,p=1;
      for(i=1;i<=b;i++)
            p*=a;
      return p;
}
void main()
{
      int x,n,p;
      clrscr();
      printf("\nEnter the Value of 'x' : ");
      scanf("%d",&x);
      printf("\nEnter the Value of 'n' : ");
      scanf("%d",&n);
      p=power(x,n);
      printf("\nPower : %d",p);
      getch();
}

Output :

Enter the Value of ‘x’ : 2

Enter the Value of ‘n’ : 3

Power : 8

No comments:

Post a Comment