Skip to main content

Zeros in Factorial Inside out !

Here is the C Program to generate a series which leads us to understand the number of zeros in a Factorial:
--------------------------------------------------------------------------------------------------------------------------
#include <stdio.h>
#include<stdlib.h>
int ZerorsInFactorial(int number);
int main(int argc, char **argv)
{
//printf("hello world\n");
    //This is to see the howmany zeros will be there in a factorial , let that be P.
    //The values P take as we move towards infinity
    int i=0;FILE *fptr;
    fptr=fopen("program.txt","w");
    if(fptr==NULL){
      printf("Error!");
      exit(1);
    }
    while(i<1000)
        {
            fprintf(fptr,"%d zeros in %d factorial\n",ZerosInFactorial(i),i);

    printf("%d zeros in %d factorial\n",ZerosInFactorial(i),i);i++;
    } fclose(fptr);
   // printf("Hello World");
return 0;
}
int ZerosInFactorial(int number)
{
    int a =number;int sum=0;
    while(a/=5){
        sum+=a;
    }
    return sum;
}
--------------------------------------------------------------------------------------------------------------------------
The output of program.txt : -

0 zeros in 0 factorial
0 zeros in 1 factorial
0 zeros in 2 factorial
0 zeros in 3 factorial
0 zeros in 4 factorial
1 zeros in 5 factorial
1 zeros in 6 factorial
1 zeros in 7 factorial
1 zeros in 8 factorial
1 zeros in 9 factorial
2 zeros in 10 factorial
2 zeros in 11 factorial
2 zeros in 12 factorial
2 zeros in 13 factorial
2 zeros in 14 factorial
3 zeros in 15 factorial
3 zeros in 16 factorial
3 zeros in 17 factorial
3 zeros in 18 factorial
3 zeros in 19 factorial
4 zeros in 20 factorial
4 zeros in 21 factorial
4 zeros in 22 factorial
4 zeros in 23 factorial
4 zeros in 24 factorial
6 zeros in 25 factorial
6 zeros in 26 factorial
6 zeros in 27 factorial
6 zeros in 28 factorial
6 zeros in 29 factorial
7 zeros in 30 factorial
7 zeros in 31 factorial
7 zeros in 32 factorial
7 zeros in 33 factorial
7 zeros in 34 factorial
8 zeros in 35 factorial
8 zeros in 36 factorial
8 zeros in 37 factorial
8 zeros in 38 factorial
8 zeros in 39 factorial
9 zeros in 40 factorial
9 zeros in 41 factorial
9 zeros in 42 factorial
9 zeros in 43 factorial
9 zeros in 44 factorial
10 zeros in 45 factorial
10 zeros in 46 factorial
10 zeros in 47 factorial
10 zeros in 48 factorial
10 zeros in 49 factorial
12 zeros in 50 factorial
12 zeros in 51 factorial
12 zeros in 52 factorial
12 zeros in 53 factorial
12 zeros in 54 factorial
13 zeros in 55 factorial
13 zeros in 56 factorial
13 zeros in 57 factorial
13 zeros in 58 factorial
13 zeros in 59 factorial
14 zeros in 60 factorial
14 zeros in 61 factorial
14 zeros in 62 factorial
14 zeros in 63 factorial
14 zeros in 64 factorial
truncated......
--------------------------------------------------------------------------------------------------------------------------

Here there is two series of number i.e one on left side and other on the right side.

1. So who they can be related algebraically ?
 a. Let us analyze the first series : 
0[0],1[5],2[10],3[15],4[20],6[25],7[30],8[35],9[40],10[45],12[50],13[55],14[60],15[65],16[70],18[75],19[80],20[85],21[90],22[95],24[100],25[105],26[110],27[115],28[120],31[125],32[130],33[135],


--------------------------------------------------------------------------------------------------------------------------
Program to analyze different sequences : 
#include <stdio.h>
#include<stdlib.h>
int ZerorsInFactorial(int number);
int main(int argc, char **argv)
{
//printf("hello world\n");
    //This is to see the howmany zeros will be there in a factorial , let that be P. 
    //The values P take as we move towards infinity
    int i=0;FILE *fptr,*fptr1,*fptr2,*fptr3;int temp=-1;int temp2;int count=1;int diffSeq=1;
    fptr=fopen("program.txt","w");
    fptr1=fopen("program1.txt","w");
     fptr2=fopen("DifferenceSequence.txt","w");
     fptr3=fopen("FirstTermOfDifferenceSequ.txt","w");
    if(fptr==NULL){
      printf("Error!");
      exit(1);
    }
    while(i<10000)
        {
            fprintf(fptr,"%d zeros in %d factorial\n",ZerosInFactorial(i),i);
        if(temp!=ZerosInFactorial(i))
        {
            fprintf(fptr1,"%d[%d]{%d},\n",ZerosInFactorial(i),i,(ZerosInFactorial(i)%5));
            temp2=ZerosInFactorial(i)-temp;
           
            count=1;
            while(temp2>1)
            {   
                if((temp+count)-(diffSeq)<6){
                    fprintf(fptr3,"%d\n",temp+count);
                }
                fprintf(fptr2,"%d\n",temp+count) ;
                diffSeq=temp+count;
                count++;
                temp2--;
            }
             temp=ZerosInFactorial(i);
        }
        
    printf("%d zeros in %d factorial\n",ZerosInFactorial(i),i);i++;
    } fclose(fptr);
   // printf("Hello World");
return 0;
}
int ZerosInFactorial(int number)
{
    int a =number;int sum=0;
    while(a/=5){
        sum+=a;
    }
    return sum;
}

--------------------------------------------------------------------------------------------------------------------------

Comments

Popular posts from this blog

Event Sourcing with CQRS.

  The way event sourcing works with CQRS is to have  part of the application that models updates as writes to an event log or Kafka topic . This is paired with an event handler that subscribes to the Kafka topic, transforms the event (as required) and writes the materialized view to a read store.

GraphQL microservices (GQLMS)

I'm curios of GraphQL !     -  GraphQL is an open-source data query and manipulation language for APIs, and a runtime for fulfilling queries with existing data. GraphQL was developed internally by Facebook in 2012 before being publicly released in 2015. It should be solving a problem in querying data !     -GraphQL lets you ask for what you want in a single query, saving bandwidth and reducing waterfall requests. It also enables clients to request their own unique data specifications. A case study ?!    -https://netflixtechblog.com/beyond-rest-1b76f7c20ef6 So, This is just another database technoloy ?  -  No. GraphQL is often confused with being a database technology. This is a misconception, GraphQL is a   query language   for APIs - not databases. In that sense it’s database agnostic and can be used with any kind of database or even no database at all. Source:   howtographql.com