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.

Procedure to enable wireless LAN adapter in vmware!

I have went to find the way in which wlan in Kali Linux could be made listed my airmon-ng command. Most of the videos and posts suggested me that it is necessary to have another wi-fi adapter to have connected to wifi network. But this is not necessary. The procedure to do this is as follows: 1. Download this package in Virtual Machine(Kali linux) " http://wireless.kernel.org/download/compat-wireless-2.6/compat-wireless-2010-06-26-p.tar.bz2" 2.Unzip this package in terminal i.e navigate to place where you have downloaded this file , say desktop then type : cd Desktop for unzip type : tar -jxvf compat-wireless-2010-06-26-p.tar.bz2 3. Navigate into the uncompressed directory and type: i."make unload"  (only words within the quotes are the commands) ii."make load" Done!  now airmon-ng  should have the list of the required devices.