Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include <stdio.h> int main() { int n, i; unsigned long long factorial = 1; prin

ID: 3863517 • Letter: #

Question

#include <stdio.h>

int main()
{
int n, i;
unsigned long long factorial = 1;

printf("Enter an integer: ");
scanf("%d",&n); //Taking input and storing in 'n'

// If user enters a negative integer
if (n < 0)
printf("Error! Invalid Input. ");

else
{
for(i=1; i<=n; i++)
{
factorial *= i; // factorial = factorial*i;
}
printf("Factorial of %d = %llu ", n, factorial);
}

return 0;
}//end function main

THIS IS MY CODE, I AM HAVING TROUBLE MAKING IT RECOGNIZE NON-INTEGER INPUTS AS INVALID, HOW CAN I DO THIS?

Explanation / Answer

In the code , we have the statement like this :

unsigned long long factorial = 1;

This long long is variable only for integer. So in order to make it non integer , we can use float or double instead of long long variable.