Home » Ask & Discuss » Other Courses » Computer Applications « Back to Discussion
Computer Applications
Comments (3)
hello dear,plz check the below program..well it is checked and perfectly working
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
struct Power { int Is; long Base, Expon; } is_power(long n)
{
struct Power result;
result.Is = 1;
result.Base = n;
result.Expon = 1;
return result;
}
int main(int argc, char *argv[])
{
long n;
char *end;
struct Power is;
if (argc < 2) {
fputs("Provide a number, please...\n", stderr);
exit(EXIT_FAILURE);
}
n = strtol(argv[1], &end, 10);
if (*end != '\0')
printf("Whatever garbage you mean by \"%s\" will be "
"ignored.\n", end);
if (errno == ERANGE)
printf("The number you wrote is too large or too small, "
"let's pretend you wrote %ld.\n", n);
is = is_power(n);
if (is.Is)
printf("%ld is a perfect power as it equals %ld**%ld.\n"
n, is.Base, is.Expon);
else
printf("%ld is not a perfect power.");
return 0;
}












}