Skip to main content

How to find Power of a number in C

 How to find Power of a number in C: -

In this program we will calculate the power of a number using C programming. We want to calculate the power of any given number so you need to multiply that particular number power of time.

Ex:-

  1. Let suppose number is 24 so we need to multiply with 4 times of 2. That is 2*2*2*2=16.


ALGORITHMS:-

Step 1– Enter the base number, the number in which you just want to find the power of the number.
Step 2– Enter the exponential, the power of the number.
Step 3– Initialize while loop, while the exponential is not equal to zero.
                (i) do temp*number and store it in the temp.
                 (ii) now reduce the exponential with -1.
                  Here you got the power of the number.
Step 4– Now print the temp variable.
Step 5- Stop.

CODE: -

#include<stdio.h>
int main()
{
    int base,exp=1,temp=1;
    printf("Enter the base value: ");
    scanf("%d",&base);
    printf("Enter the exp value: ");
    scanf("%d",&exp);
    while(exp!=0)
    {
        temp=temp*base;
        exp--;
    }
    printf("the value of power is %d",temp);
    return 0;
    
}


OUTPUT:-

FOLLOW THIS WEBPAGE FOR MORE NEW PROGRAMS AND CODING SOLUTIONS.





Comments

Popular posts from this blog

Calculate the sum of elements in an array.

  HOW TO CALCULATE THE SUM OF THE ELEMENT IN A GIVEN ARRAY: - We will learn how to find the sum of elements in an array is an easy task when you know how to iterate through array elements. In this problem, we will explain your C approach to find the sum of array elements inputted by the user. Here is the solution to this query in C Languageguage.   ALGORITHMS: STEP 1:-   Input the size of the array and store the value in m and arr[m]. STEP 2 : - To store the sum of array elements, initialize a variable sum = 0. STEP 3: -To find the sum of all elements, iterate through each element  and add the current element to the sum. STEP 4: - Inside the loop add the current array element to sum i.e.                 sum = sum + arr[i] or sum += arr[i]. CODE:- #include <stdio.h> int  main() {      int  i,num,a[ 100 ],sum= 0 ;     printf( "Enter the value of number:...

How to find the Tringle is Valid or Not in C

 How to find the Tringle is Valid or Not in C:- Code:- #include <stdio.h> int  main() {        int  side_1,side_2,side_3;        int  a,b,c;       printf( "enter the value of sides:" ); scanf( "%d\n %d\n %d" ,&side_1,&side_2,&side_3);       a= ((side_1*side_1)==((side_2*side_2)+(side_3*side_3)));       b= ((side_2*side_2)==((side_1*side_1)+(side_3*side_3)));       c= ((side_3*side_3)==((side_1*side_1)+(side_2*side_2)));       if  (a || b || c)      {         printf( "The triangle is valid" );      }       else      {...