The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
if(x <= 0) { printf("Invalid integer entered!n"); } else if( (x % BASE) != 0) { printf("%i is not a power of 3", x); } ex = 0 ; while ( x % BASE == 0) { x = x / BASE ; ex ++ ; } printf("%i is a power of 3, exponent = ", x, ex); return 0; }
#include <stdio.h>
#include <math.h>
#define BASE 3
int main()
{
int x, ex ;
printf("Enter a positive integer: ");
scanf("%i", &x);
if(x <= 0)
{
printf("Invalid integer entered!n");
}
else if( (x % BASE) != 0)
{
printf("%i is not a power of 3", x);
}
ex = 0 ;
while ( x % BASE == 0)
{
x = x / BASE ;
ex ++ ;
}
-----------