Write a program that asks the user to enter a positive integer  then prints the factorial inverse  (fact-inverse) of  if . Example: the fact-inverse of 24 is 4 (as 24 = 4!), the fact-inverse of 120 is 5 (as 120 = 5!). If the number is not a factorial, the program prints the message “value not found”.

Examples of execution:

Enter a value? 120
The fact-inverse is 5       

Enter a value? 9
Value not found


Difficulty level
This exercise is mostly suitable for students
#include<stdio.h>

void main()
{
	int f, fact, i;

	do{
		printf("Enter a positive integer: ");
		scanf("%d",&f);
	}while(f<=1);

	fact=1;
	i=0;
	while(fact<f)
		fact*=++i;

	if(fact==f)
		printf("The fact-inverse is %d\n",i);
	else
		printf("Value not found\n");
}

Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Implementation of a stack to hold elements of 2 different types