Wednesday, 22 August 2018

C Program forCalculate Power & and Inverse of any Variable | C Program to Calculate the Power of a Number | Basic C Program to Calculate the Power of a Number Using For Loop and IF Else

Calculate Power & and Inverse of any Variable C Program

 C Program to Calculate the Power of a Number 

Basic C Program to Calculate the Power of a Number Using For Loop and If - Else

#include <stdio.h>
main()
{
/* This Program is done by Anupam Dutta aka King Anupam dutta */
int i,a,b; /* declaration of variable */
float mult=1.0; /* a float variable "mult" declared and initialised */
printf("\nEnter a Value:\n");
scanf("%d",&a);
printf("\nEnter the Power of the Value (^x):\n");
scanf("%d",&b);
if(b>0)  /*This single program can calculate power of a variable and as well as the inverse of the variable, so I am putting a "if - else" condition to give a choise that if it is less than zero then it will form the inverse calculation & if it will be greater than zero then it will conduct the power calculation of the Veriable*/
{
for(i=1;i<=b;i++)
{
mult=mult*a;
}
}
else if(b<0)
{
for(i=b;i<0;i++)
{
mult=mult/a;
}
}
else  /*If the condition value is equal to zero at any given time then we all know that if  power of  a number is 0, then its value is one, So here we initialised the mult as value 0.*/
{
mult=1.0; /*initialised the mult as value 0.*/
 printf("Enter the Currect Power Value (Value > 0 or Value < 0 ) If Value is Equal to Zero then   Value Will be %f",mult);
}
printf("\n The Value : \n %d ^ %d Will Be = %f \n",a,b,mult); /*Printing the ultimate result*/
main();/*Calling the main function for creating a loop & Continuing the whole program*/
getch();
}

PubG

PUBG Live