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;
}





21 comments:

  1. Anubhav Shrivastava3/26/11, 6:44 PM

    Helpful post...thank you

    ReplyDelete
  2. this program shows segmentation fault in linux...

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

    ReplyDelete
  4. It is realy very helpfull for students

    ReplyDelete
  5. questns bagunayi boss!!!

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete
  7. help me to calculate the power by using for loop

    ReplyDelete
    Replies
    1. #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;




      }

      Delete
    2. #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);
      }

      Delete
  8. very helpful

    ReplyDelete
  9. wap to c language
    1
    22
    333
    4444
    55555

    ReplyDelete
    Replies
    1. #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");
      }
      }

      Delete
    2. #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++;
      }
      }

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

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

    ReplyDelete
  11. /****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;
    }

    ReplyDelete
  12. 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

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

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

    ReplyDelete