Skip to content

Instantly share code, notes, and snippets.

@CraigRodrigues CraigRodrigues/factorization.c Secret
Created Jul 28, 2016

What would you like to do?
CS50x Coding Contest 2016 Practice - Factorialization
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cs50.h"
int main(void)
int num = GetInt();
int factorial = 1;
for (int i = num; i > 0; i--)
factorial *= i;
printf("%i", factorial);
return 0;

This comment has been minimized.

Copy link
Owner Author

commented Jul 28, 2016

Write a program that takes an integer as input and outputs its factorial.

Note that the CS50 Library's header file must be included with double quotes (i.e., #include "cs50.h") instead of angled brackets because of how it's installed on HackerRank's servers.

Odds are you will find GetInt and printf of interest!

Input Format

An integer number.



Output Format

The factorial of the inputted number, as an integer.

Sample Input

Sample Output


The factorial of a number, n, is n × (n - 1) × (n - 2) ... × 2 × 1. For example, the factorial of 5 is 5 × 4 × 3 × 2 × 1 = 120.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.