Showing posts with label calculate power in C. Show all posts
Showing posts with label calculate power in C. Show all posts

Friday, 3 August 2012

Find Power of A Number in C


#include<stdio.h>
#include<conio.h>
void main()

{
  int pow,num,i=1;
  unsigned  long int sum=1;

  printf("\nEnter your number == ");
  scanf("%d",&num);

  printf("\nEnter the desired power ==");
  scanf("%d",&pow);

  while(i<=pow)
  {
      sum=sum*num;
      i++;
  }

  printf("\n%d to the power %d is: %ld",num,pow,sum);
  getche();
}

Friday, 13 July 2012

Calculate Power Of A Number in C


#include<stdio.h>
#include<conio.h>
void main()
{
long int a,b,c,i,j,d,u;

clrscr();

printf("enter base =");
scanf("%ld",&a);

u=a;

printf("\nenter exponent =");
scanf("%ld",&b);


for(i=0;i<b;i++)
{

    c=a*u;
    a=c;

  }


if(b==1)
{
c=c/u;

}

 printf("%ld",c);
 getch();
 }