MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / main

Function main

Hackerrank_problems/Extra Long Factorials/solution.C:3–28  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1#include <stdio.h>
2
3int main()
4{
5 int n,a[500],c=0,temp,i; //initializing an integer , array, integer c=0, temp,i.
6 a[0]=1; //assigining or storing the 0th position or the first position in array with 1.
7 scanf("%d",&n); //Enter the integer.
8 for(;n>=2;n--) //looping from the value of n till it is greater than equal to 2.
9 {
10 temp=0; //initializing temp=0
11 for(i=0;i<=c;i++) //looping from i=0 till i is less than equal to value of c
12 {
13 temp=(a[i]*n)+temp; //multiplying the value in a[i]with n and then adding it with temp's previous value and storing the total value in temp (which becomes the new value of temp)
14 a[i]=temp%10; //storing the temp%10 value in a[i]
15 temp=temp/10; //now temp's value = temp/10
16 }
17 while(temp>0) //looping till temp>0
18 {
19 a[++c]=temp%10; //a{++c] means incrementing the value of c and storing the value=temp/10
20 temp=temp/10; //temp's value =temp/10
21 }
22 }
23 for(i=c;i>=0;i--)
24 printf("%d",a[i]); //printing the value of array
25
26
27 return 0;
28}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected