FIND POWER OF A NUMBER USING C PROGRAM






How to calculate power of a number in c

How to write power in c

#include<stdio.h>
int main(){
  int pow,num,i=1;
  long int sum=1;
  printf("\nEnter a number: ");
  scanf("%d",&num);
  printf("\nEnter power: ");
  scanf("%d",&pow);
  while(i<=pow){
            sum=sum*num;
            i++;
  }
  printf("\n%d to the power %d is: %ld",num,pow,sum);
  return 0;
}





31 comments:

Anubhav Shrivastava said...

Helpful post...thank you

Anonymous said...

this program shows segmentation fault in linux...

Shahid said...

Thanks alot my brother for helping us....................

Diwakar Mishra said...

thanx

Anuj said...

It is realy very helpfull for students

Anonymous said...

questns bagunayi boss!!!

Anonymous said...

Thanks

Anonymous said...
This comment has been removed by the author.
Anonymous said...

help me to calculate the power by using for loop

Unknown said...

#include
using namespace std;
int main()
{
int n,p,temp,i;
int total=0;
cout<<"Enter the number";
cin>>n;
cout<<"power of ";
cin>>p;
temp = n;
for(i=1;i<p;i++)
{
total = temp*n;
temp = total;


}
cout<<temp;
system("PAUSE");
cin.get();
return 0;




}

Anonymous said...

very helpful

Unknown said...

wap to c language
1
22
333
4444
55555

Anand said...

#include
main()
{
int i, j, k = 0;
for(i = 1; i <= 5; i++)
{
++k;
for(j = 1; j <= i; j++)
printf("%d",k);
printf("\n");
}
}

Rocky said...

#include
void main()
{
int n,i,j=1,k;
printf("enter n:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(k=1;k<=i;k++)
{
printf("%d",j);
}
printf("\n");
j++;
}
}

Unknown said...

#include
int main()
{
int num;
int pow;
int sum =1;
printf("\n enter the number \n");
scanf("%d",&num);
printf("\n enter the power of \n");
scanf("%d",&pow);

fo(;pow;pow--)
sum = sum *num;

printf("\n sum = %d \n", sum);
}

Nikhil said...

Program to enter the numbers till the user wants and at the end it should display the count of positive, negative and zeros entered.

Anonymous said...

/****Program to input 10numbers from the user and display whether it is even or odd****/
#include
#include
int main(void)
{
int number_of_terms=10;//Total number of input from user
int number[10];//Array to store the numbers given from users
int i;
printf("Enter 10 integers\n");
for(i=1;i<=10;i++)
scanf("%d",&number[i]);
i=1;
while(i!=(number_of_terms+1))
{
if(number[i]%2==0)
{
printf("%d is Even\n",number[i]);
}
else
{
printf("%d is Odd\n",number[i]);
}
i++;
}
getch();
return 0;
}

Unknown said...

Can anyone tell how to return the square of any given number in c...without using math.h,looping mechanisms and * sign..and ya it is possible..not kidding

Anonymous said...

x^2/m+x^5/m^3+x^8/m^5+x^11/m^7.............
please help........

RavindrA said...

I=j=1:
while(i<=1)
{
while(j<=i)
{
printf("%d",i);
}
printf("\n");
I++;
}

Anonymous said...

WAP in c to display follwing o/p....plz help
*
* *
* * *
* * * *
* * * * *

StudyWard Education said...

/*
WAP in c to display follwing o/p....plz help
*
* *
* * *
* * * *
* * * * *


*/

#include
void main()
{
int row,col,i,j;
printf("enter the no. of rows and columns\n");
scanf("%d \n %d",&row,&col);

for(i=0;i0)
printf(" ");
else
printf("*");
}
printf("\n");
}
}

StudyWard Education said...
This comment has been removed by the author.
StudyWard Education said...

#include
void main()
{
int row,col,i,j;
printf("enter the no. of rows and columns\n");
scanf("%d \n %d",&row,&col);
for(i=0;i0)
printf(" ");
else
printf("%d",i+1);
}
printf("\n");
}
}

computerFlashes said...


#include
int main()
{
int x,i,k,j;
printf("Enter any number \n ");
scanf("%d",&x);
for (i=1;i<=x;i++){
for(k=1;k<=i;k++)
printf("*");
for(j=1;j<=k*2;j++)
printf(" ");
printf("\n");}
return 0;

}

Unknown said...

for C# how to calculate the power of num

{
int num;
Console.WriteLine("enter the value");
num = Convert.ToInt32(Console.ReadLine());

num = num * num;

Console.WriteLine("power of given no = {0}",num);
Console.ReadLine();
}

Unknown said...

A program using for loop to find out X to the power N to the power M

#include
int main(){
int pow1,pow2,num,i;
long int sum1=1,sum2=1;
printf(" Enter a number: ");
scanf("%d",&num);
printf("\n Enter power 1: ");
scanf("%d",&pow1);
printf("\n Enter power 2: ");
scanf("%d",&pow2);



for(i=1;i<=pow1;i++)
{

sum1=sum1*num;

}
for(i=1;i<=pow2;i++)
{

sum2=sum2*sum1;

}
printf("\n%d to the power %d to the power %d is: %ld",num,pow1,pow2,sum2);
return 0;
}

Unknown said...
This comment has been removed by the author.
Unknown said...

Why you all are taking extra variable?

#include
int main()
{
int i; // you can take this value using scanf also.
for(i = 1; i <= 5; i++)
{
for(int j = 1; j <= i; j++)
{
printf("%d ",i); // print i here
}
printf("\n");
}
return 0;
}

Unknown said...

#include
int main()
{
int num,power,i,ans=1;
scanf("%d",&num);
scanf("%d",&power);
for(i=0;i<power;i++);
{
ans=num*ans;
}
printf("%d",ans);
return (0);

}

ans is not coming right

Unknown said...

Why does in for loop the formula is power= power * base? What does this mean? Help pls.