#include <stdio.h>
int main(void)
{
int base, index, tmp;
float res = 1.0;
printf("\nEnter the base and index :");
scanf("%d%d",&base, &index);
tmp = index;
/* First method using a simple if() condition */
if(index < 0)
index *= -1;
while(index > 0)
{
res *= base;
index--;
}
/* Second method using a while() loop that runs either way */
/*
while(index != 0)
{
res *= base;
if(index > 0) index--;
else index++;
}
*/
if(tmp < 0)
{
res = 1 / res;
}
printf("\n%d raised to %d is %f", base, tmp, res);
return 0;
}
int main(void)
{
int base, index, tmp;
float res = 1.0;
printf("\nEnter the base and index :");
scanf("%d%d",&base, &index);
tmp = index;
/* First method using a simple if() condition */
if(index < 0)
index *= -1;
while(index > 0)
{
res *= base;
index--;
}
/* Second method using a while() loop that runs either way */
/*
while(index != 0)
{
res *= base;
if(index > 0) index--;
else index++;
}
*/
if(tmp < 0)
{
res = 1 / res;
}
printf("\n%d raised to %d is %f", base, tmp, res);
return 0;
}
No comments:
Post a Comment
kiss on google ads if you are anonymous because your ip is trackable.thank you.
......from.admin